예제 #1
0
     //商品流水帐
     $cogememo = "销售商品类型为" . $productname . "的刷卡器设备:" . $paycardkey;
     $cogelisttype = "3";
     $cogetype = 1;
     //0为增加 , 1为减少
     commglide($storageid, $productid, $quantity, $cogememo, $cogelisttype, $loginstaname, $listid, $listno, $cogetype, $date);
     $allmoney += $price * $quantity;
     //销售总额
 }
 //生成分行往来对帐单
 $ctatmemo = "应收" . $cusname . "客户" . $allmoney . "元";
 $cactlisttype = "3";
 $lessenmoney = 0;
 currentaccount(1, $cusid, $allmoney, $lessenmoney, $ctatmemo, $cactlisttype, $loginstaname, $listid, $listno, $date);
 if ($allmoney != 0) {
     changemoney(1, $cusid, $allmoney, 0);
     //第四位0代表正,1代表负数
 }
 //生成帐户流水帐
 $chgememo = "销售单收取" . $cusname . "客户" . $allmoney . "元";
 $chgelisttype = "3";
 $cogetype = 0;
 //0为收款 , 1为付款
 cashglide($accountid, $allmoney, $chgememo, $chgelisttype, $loginstaname, $listid, $listno, $cogetype, $date);
 $query = "insert into tb_cus_stock(\n\t                fd_stock_no          ,   fd_stock_date  ,fd_stock_cusid   , fd_stock_cusno,\n\t\t\t\t\tfd_stock_cusname     ,\tfd_stock_skfs   ,fd_stock_shaddress  ,fd_stock_allmoney,\n\t\t\t\t\tfd_stock_allcost    ,fd_stock_saleid     ,fd_stock_datetime  ,fd_stock_state\n\t                )values(\n\t                '{$listno}'           ,   '{$date}'      ,'{$cusid}'         , '{$cusno}',\n\t\t\t\t\t'{$cusname}'          ,   '{$skfs}'      ,'{$shaddress}'\t   , '{$allmoney}',\n  \t\t\t\t\t'{$allmoney}'         ,   '{$listid}'    ,   now()         ,  '1'\n\t                )";
 $db->query($query);
 //插入单据资料
 $cus_listid = $db->insert_id();
 //取出刚插入的记录的主关键值的id
 for ($i = 0; $i < count($arr_data); $i++) {
     $paycardid = $arr_data[$i]['paycardid'];
function create_erpinmoney($memid, $paymoney)
{
    $db = new mssale_test();
    $db2 = new mssale_test();
    $dberp = new erp_test();
    $query = "select * from tb_organmem where fd_organmem_id = '{$memid}'";
    $db->query($query);
    if ($db->nf()) {
        $db->next_record();
        $insert_cusid = $db->f(fd_organmem_cusid);
        $cusno = $db->f(fd_organmem_cusno);
        $cusname = $db->f(fd_organmem_cusname);
        $phone = $db->f(fd_organmem_phone);
        $mobile = $db->f(fd_organmem_mobile);
        $address = $db->f(fd_organmem_address);
        $comnpany = $db->f(fd_organmem_comnpany);
        $linkman = $db->f(fd_organmem_linkman);
        $email = $db->f(fd_organmem_email);
        $province = $db->f(fd_organmem_province);
        $city = $db->f(fd_organmem_city);
        $county = $db->f(fd_organmem_county);
        $memid = $db->f(fd_order_memeberid);
        //绑定ERP客户
        if (empty($cusname)) {
            $cusno = "ZB" . strtoupper(c($comnpany)) . randstr() . "";
            //生成客户编号
            $query = "select * from tb_webcustomer where fd_webcus_allname = '{$comnpany}' and fd_webcus_organid = '1'";
            $dberp->query($query);
            if ($dberp->nf()) {
                $dberp->next_record();
                $webmemid = $dberp->f(fd_webcus_id);
            } else {
                $query = "INSERT INTO tb_webcustomer (\n                    fd_webcus_no          ,   fd_webcus_name      ,  fd_webcus_allname      ,\n                    fd_webcus_address     ,   fd_webcus_phone1    ,  fd_webcus_quyuid       ,    \n                    fd_webcus_newtime     ,   fd_webcus_provinces ,  fd_webcus_city         ,  \n                    fd_webcus_county      ,   fd_webcus_organid   ,  fd_webcus_linkman      ,  \n                    fd_webcus_manphone    ,   fd_webcus_email     \n                    )VALUES(\n                    '{$cusno}'              ,   '{$comnpany}'          ,  '{$comnpany}'           ,\n                    '{$address}'            ,   '{$phone}'             ,  '{$quyuid}'             ,    \n                    now()                 ,   '{$province}'          ,  '{$city}'               ,  \n                    '{$county}'             ,   '1'                  ,  '{$linkman}'            ,  \n                    '{$mobile}'             ,   '{$email}'\n                    )";
                $dberp->query($query);
                $webmemid = $dberp->insert_id();
            }
            $query = "select * from tb_customer where fd_cus_allname = '{$comnpany}' and fd_cus_organid = '1'";
            $dberp->query($query);
            if ($dberp->nf()) {
                $dberp->next_record();
                $insert_cusid = $dberp->f(fd_cus_id);
                $cusno = $dberp->f(fd_cus_no);
            } else {
                $query = "INSERT INTO tb_customer(\n                   fd_cus_no          ,   fd_cus_name      ,  fd_cus_allname      ,\n                   fd_cus_address     ,   fd_cus_phone1    ,  fd_cus_quyuid       ,    \n                   fd_cus_newtime     ,   fd_cus_organid   ,  fd_cus_iswebuse     ,  \n                   fd_cus_provinces   ,   fd_cus_city      ,  fd_cus_county       ,   \n                   fd_cus_linkman     ,   fd_cus_manphone  ,  fd_cus_email        ,  \n                   fd_cus_credit \n                   )VALUES (\n                   '{$cusno}'           ,   '{$comnpany}'      ,  '{$comnpany}'         ,\n                   '{$address}'         ,   '{$phone}'         ,  '{$quyuid}'           ,    \n                   now()              ,   '1'              ,  '1'                 ,  \n                   '{$province}'        ,   '{$city}'          ,  '{$county}'          ,   \n                   '{$linkman}'         ,   '{$mobile}'      ,  '{$email}'           ,  \n                   '100'  \n                   )";
                $dberp->query($query);
                $insert_cusid = $dberp->insert_id();
                //取出刚插入的记录的主关键值的id
            }
            $query = "update tb_webcustomer set fd_webcus_erpcusid = '{$insert_cusid}' where fd_webcus_id = '{$webmemid}'";
            $dberp->query($query);
            $query = "update tb_organmem set fd_organmem_cusid = '{$insert_cusid}',fd_organmem_cusno = '{$cusno}', fd_organmem_cusname = '{$comnpany}'\n                    where fd_organmem_id = '{$memid}'";
            $db->query($query);
        }
        //--------------------增加收款单功能----------------------------
        $nowdate = date("Y-m-d");
        $havesave = 0;
        $paymemo = "手机支付自动生成的收款单";
        //$paymemo = u2g($paymemo);
        if (empty($cusname)) {
            //如果客户是为空,就绑定网站注册公司为客户名称
            $cusname = $comnpany;
        }
        $quyuid = 5;
        $mscid = 11;
        $skmscid = 11;
        $skaccountid = "208";
        $pjlistno = listnumber_update2(10);
        //票据编号
        $xt = '系统';
        $query = "insert into tb_bill(\n                  fd_bill_no          ,  fd_bill_clientid , fd_bill_type         ,\n                  fd_bill_clientname  ,  fd_bill_organid  , fd_bill_accountid    ,\n                  fd_bill_money       ,  fd_bill_date     , fd_bill_memo         ,\n                  fd_bill_dealwithman ,  fd_bill_billno   , fd_bill_firstorganid ,\n                  fd_bill_billtype    ,  fd_bill_bank     , fd_bill_number       ,\n                  fd_bill_remitter    ,  fd_bill_enddate  , fd_bill_sdcrid       ,\n                  fd_bill_clientno    ,  fd_bill_iecrid   , fd_bill_isopeninvoice,\n                  fd_bill_mscompanyid ,  fd_bill_state    , fd_bill_hzdate\n                  )values(\n                  '{$pjlistno}'         , '{$insert_cusid}'     , '1'              ,\n                  '{$cusname}'          , '1'                 , '{$skaccountid}'   ,\n                  '{$paymoney}'         , '{$nowdate}'          , '{$paymemo}'       ,\n                  '{$xt}'               ,  ''                 , '1'              ,   \n                  '4'                 ,  ''                 , ''               ,\n                  ''                  , '{$nowdate}'          , '{$quyuid}'        ,\n                  '{$cusno}'            , ''                  , '1'              ,\n                  '{$skmscid}'          , '4'                 , now()\n                  )";
        $dberp->query($query);
        //插入付款单
        $pjlistid = $dberp->insert_id();
        //取出刚插入的记录的主关键值的id
        $sklistno = listnumber_update2(8);
        //票据编号
        $query = "insert into tb_inmoneylist (\n                  fd_inmylt_no        , fd_inmylt_clientid    , fd_inmylt_type         , \n                  fd_inmylt_clientno  , fd_inmylt_clientname  , fd_inmylt_dealwithman  ,\n                  fd_inmylt_accountid , fd_inmylt_money       , fd_inmylt_date         ,\n                  fd_inmylt_state     , fd_inmylt_memo        , fd_inmylt_datetime     ,\n                  fd_inmylt_organid   , fd_inmylt_sdcrid      , fd_inmylt_mscompanyid  ,\n                  fd_inmylt_skmscid   , fd_inmylt_billid\n                  )values(\n                  '{$sklistno}'         , '{$insert_cusid}'       , '1'                    ,\n                  '{$cusno}'            , '{$cusname}'            , '{$xt}'                  ,\n                  '{$skaccountid}'      , '{$paymoney}'           , '{$nowdate}'             ,\n                  '1'                 , '{$paymemo}'            , now()                  ,\n                  '1'                 , '{$quyuid}'             , '{$skmscid}'             ,\n                  '{$skmscid}'          , '{$pjlistid}'\n                  )";
        $dberp->query($query);
        $sklistid = $dberp->insert_id();
        //取出刚插入的记录的主关键值的id
        //生成客户往来对帐单
        $ctatmemo = "手机支付自动生成的收款单收取" . $paymoney . "元";
        $cactlisttype = "8";
        $addmoney = 0;
        zbcurrentaccount(1, $insert_cusid, $addmoney, $paymoney, $ctatmemo, $cactlisttype, $xt, $sklistid, $sklistno, $nowdate, $quyuid, $skmscid);
        changemoney(1, $insert_cusid, $paymoney, 1, 1, $quyuid, $skmscid, 1);
        //修改应收应付款函数,0代表正,1代表负数
        changeaccount($skaccountid, $paymoney, 0);
        //调用修改帐户金额的函数
        //生成帐户流水帐
        $chgememo = "手机支付自动生成的收款单收取" . $paymoney . "元";
        $chgelisttype = "8";
        $cogetype = 0;
        //0为收款 , 1为付款
        cashglide($skaccountid, $paymoney, $chgememo, $chgelisttype, $xt, $sklistid, $sklistno, $cogetype, $nowdate);
    }
}
 } else {
     $allmoney = 0;
     $query = "select * from tb_inmoneylist where fd_inmylt_id = '{$listid}'";
     $db->query($query);
     if ($db->nf()) {
         $db->next_record();
         $allmoney = $db->f(fd_inmylt_money);
         $vclienttype = $db->f(fd_inmylt_type);
         $vclientid = $db->f(fd_inmylt_clientid);
     }
     //生成往来对帐单
     $ctatmemo = "收款单收取" . $allmoney . "元";
     $cactlisttype = "8";
     $addmoney = 0;
     currentaccount($vclienttype, $vclientid, $addmoney, $allmoney, $ctatmemo, $cactlisttype, $loginstaname, $listid, $listno, $date);
     changemoney($vclienttype, $vclientid, $allmoney, 1);
     //修改应收应付款函数,0代表正,1代表负数
     // changeaccount($accountid , $allmoney , 0);    //调用修改帐户金额的函数
     //生成帐户流水帐
     $chgememo = "收款单收取" . $allmoney . "元";
     $chgelisttype = "8";
     $cogetype = 0;
     //0为收款 , 1为付款
     cashglide($accountid, $allmoney, $chgememo, $chgelisttype, $loginstaname, $listid, $listno, $cogetype, $date);
     $query = "update tb_inmoneylist set fd_inmylt_state = 1 , fd_inmylt_datetime = now() \n                       where fd_inmylt_id = '{$listid}'";
     $db->query($query);
     //修改付款单
     require "../include/alledit.2.php";
     Header("Location: {$gotourl}");
 }
 break;
예제 #4
0
                 $productscope = $arr_data[$valeu]['productscope'];
                 $producttypeid = $arr_data[$valeu]['producttypeid'];
                 $intlenght = strlen($arr_endint);
                 for ($arr_startint; $arr_startint <= $arr_endint; $arr_startint++) {
                     $arr_startint = $arr_startint + 0;
                     $newdata = isbuzero($intlenght, $arr_startint);
                     $paycardid = trim($arr_cart . $newdata);
                     $query = "insert into tb_paycard(\n\t\t\t\t\t\t\t\t\t\tfd_paycard_key,fd_paycard_no,fd_paycard_product,fd_paycard_batches,fd_paycard_stockprice,\n\t\t\t\t\t     \t            fd_paycard_paycardtypeid ,fd_paycard_scope,fd_paycard_memo,fd_paycard_datetime,fd_paycard_state\n\t\t\t\t\t     \t           )values('{$paycardid}','{$paycardid}','{$productid}','{$batches}','{$price}','{$producttypeid}','{$productscope}',\n\t\t\t\t\t     \t             '{$date} 该刷卡器采购入库','{$date}','1'\n\t\t\t\t\t     \t           )";
                     $db->query($query);
                 }
             }
             //生成分行往来对帐单
             $ctatmemo = "应付" . $suppname . "供应商" . $allmoney . "元";
             $cactlisttype = "1";
             currentaccount(2, $suppid, '', $allmoney, $ctatmemo, $cactlisttype, $loginstaname, $listid, $listno, $date);
             changemoney(2, $suppid, $allmoney, 1);
             //0代表正,1代表负数
         }
         $query = "update tb_paycardstock set\n\t              fd_stock_state   = 9  ,  fd_stock_datetime     = now()                \n\t              where fd_stock_id = '{$listid}' ";
         $db->query($query);
         //修改单据资料
         require "../include/alledit.2.php";
         echo "<script>alert('审批成功!');location.href='{$gotourl}';</script>";
     }
     break;
 case "dellist":
     //审批不通过
     $query = "update tb_paycardstock set fd_stock_state ='0',fd_stock_memo='{$memo_z}'  where fd_stock_id = '{$listid}' ";
     $db->query($query);
     //修改单据资料
     require "../include/alledit.2.php";
예제 #5
0
function sc_sjstockorder($orderid)
{
    $dbshop = new DB_shop();
    $db = new DB_test();
    $dberp = new DB_erp();
    $query = "select * from web_order where fd_order_id = '{$orderid}'";
    $dbshop->query($query);
    if ($dbshop->nf()) {
        $dbshop->next_record();
        $memeberid = $dbshop->f(fd_order_memeberid);
        $ishaveinvoice = $dbshop->f(fd_order_isfp);
        $wlyf = $dbshop->f(fd_order_wlfy);
        $wlzftype = $dbshop->f(fd_order_wlzftype);
        $shopid = $dbshop->f(fd_order_shopid);
        $sjallmoney = $dbshop->f(fd_order_sjallmoney);
        $allmoney = $dbshop->f(fd_order_allmoney);
        $mscompanyid = $dbshop->f(fd_order_mscid);
        $srmoney = $allmoney - $sjallmoney;
    }
    if ($ishaveinvoice == 0) {
        $ishaveinvoice = 1;
    } else {
        $ishaveinvoice = 0;
    }
    if (empty($mscompanyid)) {
        $mscompanyid = 2;
    }
    //查找对应供应商
    $query = "select * from tb_mscompany where fd_msc_id = '{$mscompanyid}'";
    $dberp->query($query);
    if ($dberp->nf()) {
        $dberp->next_record();
        $msc_sdcrid = $dberp->f(fd_msc_sdcrid);
    }
    $query = "select * from tb_organmem where fd_organmem_id  = '{$memeberid}' and fd_organmem_isms = 1";
    $db->query($query);
    if ($db->nf()) {
        $db->next_record();
        $cusid = $db->f(fd_organmem_cusid);
        $query = "select * from tb_customer  where fd_cus_id = '{$cusid}'";
        $dberp->query($query);
        if ($dberp->nf()) {
            $dberp->next_record();
            $sdcrid = $dberp->f(fd_cus_wgsdcrid);
            $owlid = $dberp->f(fd_cus_id);
            $owlname = $dberp->f(fd_cus_allname);
            $owlno = $dberp->f(fd_cus_no);
            $wgmscid = $dberp->f(fd_cus_wgmscid);
            $otype = 1;
        }
        //查找对应供应商
        $query = "select * from tb_mscompany where fd_msc_id = '{$mscompanyid}'";
        $dberp->query($query);
        if ($dberp->nf()) {
            $dberp->next_record();
            $msc_sdcrid = $dberp->f(fd_msc_sdcrid);
        }
        //查找对应供应商
        $query = "select * from tb_supplier  where fd_supp_mscid = '{$mscompanyid}'";
        $dberp->query($query);
        if ($dberp->nf()) {
            $dberp->next_record();
            $suppid = $dberp->f(fd_supp_id);
            $suppno = $dberp->f(fd_supp_no);
            $suppname = $dberp->f(fd_supp_allname);
        }
        //插入采购订单主表
        $stockorderno = listnumber_update(65);
        $memo_z = "网购采购(商家)";
        $syear = date("Y", mktime());
        $smonth = date("n", mktime());
        $query = "insert into tb_stockorder(\n\t              fd_skor_listno      ,   fd_skor_suppid     , fd_skor_suppno        ,\n\t              fd_skor_suppname    ,   fd_skor_organid    , fd_skor_lddate        , \n\t              fd_skor_memo        ,   fd_skor_cgmscid    , fd_skor_sdcrid        ,\n\t              fd_skor_fkqx        ,   fd_skor_year       , fd_skor_month         ,\n\t              fd_skor_yjfhdate    ,   fd_skor_yjshdate   , fd_skor_stocktype     ,\n\t              fd_skor_paymodel    ,   fd_skor_gdr        , fd_skor_ishaveinvoice ,\n\t              fd_skor_ldr         ,   fd_skor_suplinkid  , fd_skor_suplinkname   ,\n\t              fd_skor_cgfanli     ,   fd_skor_wftpzx     , fd_skor_transporttype ,\n\t              fd_skor_state      \n\t              )values(\n\t              '{$stockorderno}'     ,   '{$suppid}'          , '{$suppno}'             ,\n\t              '{$suppname}'         ,   '1'                , now()                 ,\n\t              '{$memo_z}'           ,   '{$wgmscid}'         , '{$sdcrid}'             ,\n\t              '0'                 ,   '{$syear}'           , '{$smonth}'             ,\n\t              now()               ,   now()              , '1'                   ,\n\t              '0'                 ,   ''                 , '{$ishaveinvoice}'      ,\n\t              '{$loginstaname}'     ,   ''                 , ''                    ,\n\t              ''                  ,   ''                 , ''                    ,\n\t              '6'\n\t              )";
        $dberp->query($query);
        //插入单据资料
        $stockorderid = $dberp->insert_id();
        //插入明细表
        $query = "select * from web_orderdetail   \n                where fd_orderdetail_orderid  = '{$orderid}'";
        $dbshop->query($query);
        if ($dbshop->nf()) {
            while ($dbshop->next_record()) {
                $commid = $dbshop->f(fd_orderdetail_productid);
                $commbar = $dbshop->f(fd_orderdetail_barcode);
                $commname = $dbshop->f(fd_orderdetail_productname);
                $unitname = $dbshop->f(fd_orderdetail_unit);
                $price = $dbshop->f(fd_orderdetail_price);
                $quantity = $dbshop->f(fd_orderdetail_quantity);
                unset($comm_str);
                $comm_str = explode("@@@", readproduct($commid));
                $tmpralation = $comm_str[5];
                //对应关系3
                $dunquantity = changekg3($tmpralation, $unitname, $quantity);
                //吨数量
                if ($unitname == "令") {
                    $unit = 20;
                } else {
                    $unit = 21;
                }
                $alldunquantity += $dunquantity;
                //$allmoney += $price*$quantity;
                $query = "insert into tb_stockorderdetail(\n\t                    fd_skdrdetail_skorid    ,  fd_skdrdetail_commid       ,  fd_skdrdetail_isorgan       ,\n\t                    fd_skdrdetail_commname  ,  fd_skdrdetail_commbar      ,  fd_skdrdetail_unit          ,\n\t                    fd_skdrdetail_quantity  ,  fd_skdrdetail_price        ,  fd_skdrdetail_memo          ,\n\t                    fd_skdrdetail_organid   ,  fd_skdrdetail_dyj          \n\t                    )values(\n\t                    '{$stockorderid}'         ,  '{$commid}'                  ,  '0'                         ,\n\t                    '{$commname}'             ,  '{$commbar}'                 ,  '{$unit}'                     ,\n\t                    '{$quantity}'             ,  '{$price}'                   ,  '{$memo}'                     ,\n\t                    '{$sdcrid}'               ,  '{$dyj}'                    \n\t                    )";
                $dberp->query($query);
            }
        }
        if ($wlzftype == 2) {
            $dyj = $wlyf / $alldunquantity;
            //$allmoney = $allmoney+$wlyf;
            $query = "update tb_stockorderdetail set fd_skdrdetail_dyj = '{$dyj}' where fd_skdrdetail_skorid = '{$stockorderid}'";
            $dberp->query($query);
        }
        $query = "update tb_stockorder set fd_skor_allmoney = '{$allmoney}',fd_skor_alldunquantity = '{$alldunquantity}'\n                where fd_skor_id = '{$stockorderid}'\n               ";
        $dberp->query($query);
    } else {
        $query = "select * from tb_organmem where fd_organmem_id  = '{$memeberid}'";
        $db->query($query);
        if ($db->nf()) {
            $db->next_record();
            $cusid = $db->f(fd_organmem_cusid);
            $query = "select * from tb_mscompany where fd_msc_id = '{$mscompanyid}'";
            $dberp->query($query);
            if ($dberp->nf()) {
                $dberp->next_record();
                $sdcrid = $dberp->f(fd_msc_sdcrid);
            }
            $query = "select * from tb_customer where fd_cus_id = '{$cusid}'";
            $dberp->query($query);
            if ($dberp->nf()) {
                $dberp->next_record();
                //$sdcrid  = 1;
                $owlid = $dberp->f(fd_cus_id);
                $owlname = $dberp->f(fd_cus_allname);
                $owlno = $dberp->f(fd_cus_no);
                $otype = 1;
            }
        }
    }
    //生成应收应付转移
    //搜索对应供应商
    $query = "select * from tb_supplier where fd_supp_shopid = '{$shopid}'";
    $dberp->query($query);
    if ($dberp->nf()) {
        $dberp->next_record();
        $iwlid = $dberp->f(fd_supp_id);
        $iwlno = $dberp->f(fd_supp_no);
        $iwlname = $dberp->f(fd_supp_allname);
        $itype = 2;
        $ysyfzyno = listnumber_update(101);
        $memo_z = "网站客户应收款转移到商家应收款";
        $money = -$sjallmoney;
        $query = "insert into tb_ysyfwlzy(\n                fd_ysyfwlzy_listno    ,  fd_ysyfwlzy_owlid   , fd_ysyfwlzy_otype   ,\n                fd_ysyfwlzy_owlname   ,  fd_ysyfwlzy_owlno   , fd_ysyfwlzy_iwlid   , \n                fd_ysyfwlzy_iwlno     ,  fd_ysyfwlzy_iwlname , fd_ysyfwlzy_itype   , \n                fd_ysyfwlzy_listdate  ,  fd_ysyfwlzy_memo    , fd_ysyfwlzy_organid ,      \n                fd_ysyfwlzy_sdcrid    ,  fd_ysyfwlzy_mscid   , fd_ysyfwlzy_sqman   ,\n                fd_ysyfwlzy_money\n                )values(\n                '{$ysyfzyno}'           , '{$owlid}'             , '{$otype}'            ,\n                '{$owlname}'            , '{$owlno}'             , '{$iwlid}'            ,\n                '{$iwlno}'              , '{$iwlname}'           , '{$itype}'            ,\n                now()                 , '{$memo_z}'            , '1'                 ,\n                '{$msc_sdcrid}'         , '{$mscompanyid}'       , '{$loginstaname}'     ,\n                '{$money}'\n                )";
        $dberp->query($query);
        $listid = $dberp->insert_id();
        $query = "update tb_ysyfwlzy set fd_ysyfwlzy_state = '3' ,fd_ysyfwlzy_gzdate = now() where fd_ysyfwlzy_id = '{$listid}'";
        $dberp->query($query);
        //修改
        $query = "select * from tb_ysyfwlzy where fd_ysyfwlzy_id = '{$listid}' ";
        $dberp->query($query);
        if ($dberp->nf()) {
            $dberp->next_record();
            $listno = $dberp->f(fd_ysyfwlzy_listno);
            $owlid = $dberp->f(fd_ysyfwlzy_owlid);
            $owlno = $dberp->f(fd_ysyfwlzy_owlno);
            $owlname = $dberp->f(fd_ysyfwlzy_owlname);
            $otype = $dberp->f(fd_ysyfwlzy_otype);
            $iwlid = $dberp->f(fd_ysyfwlzy_iwlid);
            $iwlno = $dberp->f(fd_ysyfwlzy_iwlno);
            $iwlname = $dberp->f(fd_ysyfwlzy_iwlname);
            $itype = $dberp->f(fd_ysyfwlzy_itype);
            $listdate = $dberp->f(fd_ysyfwlzy_listdate);
            $money = $dberp->f(fd_ysyfwlzy_money);
            $sdcrid = $dberp->f(fd_ysyfwlzy_sdcrid);
            //配送中心id号
            $mscompanyid = $dberp->f(fd_ysyfwlzy_mscid);
            $addmoney = -$money;
            $lessenmoney = 0;
            //生成客户往来对帐单
            $ctatmemo = "应收应付款往来转移应付减少" . -$money . "元";
            $cactlisttype = "101";
            zbcurrentaccount($otype, $owlid, $addmoney, $lessenmoney, $ctatmemo, $cactlisttype, $loginstaname, $listid, $listno, $listdate, $sdcrid, $mscompanyid);
            changemoney($otype, $owlid, $money, 1, 1, $sdcrid, $mscompanyid, 1);
            //修改应付应付款函数,0代表正,1代表负数
            //--------------------转到往来单位--------------------------------
            $addmoney = 0;
            $lessenmoney = -$money;
            //生成客户往来对帐单
            $ctatmemo = "应收应付款往来转移应付增加" . -$money . "元";
            $cactlisttype = "101";
            zbcurrentaccount($itype, $iwlid, $addmoney, $lessenmoney, $ctatmemo, $cactlisttype, $loginstaname, $listid, $listno, $listdate, $sdcrid, $mscompanyid);
            changemoney($itype, $iwlid, $money, 0, 1, $sdcrid, $mscompanyid, 1);
            //修改应付应付款函数,0代表正,1代表负数
        }
    }
    //生成收入
    $memo_z = "网站会员向商家采购抵扣运费,提成,返利收入";
    $fkdno = listnumber_update(9);
    $query = "insert into tb_paymoneylist(\n              fd_pymylt_no          ,  fd_pymylt_clientid    , fd_pymylt_type         ,\n              fd_pymylt_clientname  ,  fd_pymylt_staid       , fd_pymylt_money        ,  \n              fd_pymylt_date        ,  fd_pymylt_memo        , fd_pymylt_organid      , \n              fd_pymylt_clientno    ,  fd_pymylt_sdcrid      , fd_pymylt_mscompanyid  ,\n              fd_pymylt_state       ,  fd_pymylt_paymscid\n              )values(\n              '{$fkdno}'              ,  '{$owlid}'              , '1'                    ,\n              '{$owlname}'            ,  '{$loginstaid}'         , '{$srmoney}'             ,\n              now()                 ,  '{$memo_z}'             , '1'                    ,  \n              '{$cusno}'              ,  '1'                   , '2'                    ,\n              '1'                   ,  '{$mscompanyid}'\n              )";
    $dberp->query($query);
    //插入付款单
    $fkdid = $dberp->insert_id();
    //生成客户往来对帐单
    $addmoney = $srmoney;
    $lessenmoney = 0;
    $ctatmemo = "抵扣运费,提成,返利收入,应付减少" . $srmoney . "元";
    $cactlisttype = "9";
    zbcurrentaccount(1, $owlid, $addmoney, $lessenmoney, $ctatmemo, $cactlisttype, $loginstaname, $fkdid, $fkdno, $listdate, 1, 2);
    changemoney($otype, $owlid, $srmoney, 0, 1, 1, 2, 1);
    //修改应付应付款函数,0代表正,1代表负数
    //其他收入
    $query = "select * from tb_othercompany where fd_orcy_izwz = 1";
    if ($dberp->nf()) {
        $dberp->next_record();
        $companyid = $dberp->f(fd_orcy_id);
        $company = $dberp->f(fd_orcy_allname);
    }
    $srdno = listnumber_update(13);
    $memo_z = "网站会员向商家采购运费,提成,返利收入";
    $query = "insert into tb_incomelist(\n\t            fd_incomelist_no          ,   fd_incomelist_date         ,   fd_incomelist_company      ,\n\t            fd_incomelist_staid       ,   fd_incomelist_memo         ,   fd_incomelist_organid      , \n\t            fd_incomelist_mscompanyid ,   fd_incomelist_sdcrid       ,   fd_incomelist_companyid    ,\n\t            fd_incomelist_state       ,   fd_incomelist_allmoney     ,   fd_incomelist_datetime\n\t            )values(\n\t            '{$srdno}'                  ,   now()                      ,  '{$company}'                  ,\n\t            '{$loginstaid}'             ,   '{$memo_z}'                  ,   '1'                        , \n\t            '2'                       ,   '1'                        ,   '{$companyid}'               ,\n\t            '2'                       ,   '{$srmoney}'                 ,   now() \n\t            )";
    $dberp->query($query);
    //插入单据资料
    $listid = $dberp->insert_id();
    //取出刚插入的记录的主关键值的id
    $query = "insert into tb_incomelistdetail(\n\t       \t       fd_ieltdl_incomelistid  ,  fd_ieltdl_ptteid  ,  fd_ieltdl_cost  , \n\t       \t       fd_ieltdl_memo\n\t       \t       )values(\n\t       \t       '{$listid}'               ,  '30'              ,  '{$srmoney}'         ,\n\t       \t       '{$memo}' \n\t       \t       )";
    $dberp->query($query);
    $listtype = "13";
    //单据类型
    $oppositecode = "30301-a001";
    updatesubject($listtype, $listid, $oppositecode, $cost, 0, 1);
    //0代表正,1代表负数
}
예제 #6
0
function update_erpcusfk($cusid, $fkmoney, $year, $month)
{
    //取得最新订单所属的配送中心
    $db = new DB_test();
    $query = "select fd_order_sdcrid,fd_organmem_cusname from tb_order \n\t            left join tb_organmem on fd_organmem_id = fd_order_memeberid\n\t            where fd_organmem_cusid = '{$cusid}' order by fd_order_date desc";
    $db->query($query);
    if ($db->nf()) {
        $db->next_record();
        $sdcrid = $db->f(fd_order_sdcrid);
        $cusname = $db->f(fd_organmem_cusname);
        if ($sdcrid == 1) {
            $mscompanyid = 1;
            //广州市明盛物流有限公司
        } else {
            if ($sdcrid == 2) {
                $mscompanyid = 4;
                //上海粤琳珠物流有限公司
            } else {
                if ($sdcrid == 3) {
                    $mscompanyid = 13;
                    //廊坊市明盛纸业有限公司
                } else {
                    if ($sdcrid == 4) {
                        $mscompanyid = 9;
                    } else {
                        if ($sdcrid == 5) {
                            $mscompanyid = 11;
                        }
                    }
                }
            }
        }
        $db_erp = new DB_erp();
        //自动生成单据单据编号
        $listno = listnumber_update();
        $query = "insert into tb_wzfkfy  (\n                fd_wzfkfy_no         , fd_wzfkfy_cusid            , fd_wzfkfy_money       ,\n                fd_wzfkfy_date       , fd_wzfkfy_year             , fd_wzfkfy_month       ,\n                fd_wzfkfy_sdcrid     , fd_wzfkfy_organid   \n                )values( \n                '{$listno}'            , '{$cusid}'                   , '{$fkmoney}'            ,\n                now()                , '{$year}'                    , '{$month}'              ,\n                '{$sdcrid}'            , '1'                 \n                )";
        $db_erp->query($query);
        $listid = $db_erp->insert_id();
        //更新应收款
        if ($fkmoney != 0) {
            changemoney(1, $cusid, $fkmoney, 1, 1, $sdcrid, $mscompanyid, 1);
            //第四位0代表正,1代表负数
            //生成总部往来对帐单
            $ctatmemo = "应付" . $cusname . "客户" . $fkmoney . "元";
            $cactlisttype = "115";
            $addmoney = 0;
            $lessenmoney = $fkmoney;
            $date = date("Y-m-d", mktime("0", "0", "0", date("m", mktime()), date("d", mktime()), date("Y", mktime())));
            zbcurrentaccount(1, $cusid, $addmoney, $lessenmoney, $ctatmemo, $cactlisttype, '网站自动生成', $listid, $listno, $date, $sdcrid, $mscompanyid);
            //------------------插入网站返款费用科目--------------------------
            $listtype = "115";
            //单据类型
            $flstno = "4030313-a001";
            updatesubject($listtype, $listid, $flstno, $fkmoney, 0, 1);
            //0代表正,1代表负数
        }
    }
}
예제 #7
0
function wgsalegz($listid)
{
    $db = new DB_erp();
    $db1 = new DB_erp();
    $dberp = new DB_test();
    $organtype = 1;
    $organno = "a001";
    $query = "select * from tb_salelist_2010 \n          where fd_selt_id = '{$listid}' and fd_selt_state = '92'\n         ";
    $db->query($query);
    if ($db->nf()) {
        $query = "select fd_selt_historymemo,fd_selt_ldr,fd_selt_weborderid from tb_salelist_2010 where fd_selt_id = '{$listid}'";
        $db->query($query);
        if ($db->nf()) {
            $db->next_record();
            $historymemo = $db->f(fd_selt_historymemo);
            $ldrname = $db->f(fd_selt_ldr);
            $weborderid = $db->f(fd_selt_weborderid);
        }
        $liststate = 1;
        $query = "update tb_salelist_2010 set fd_selt_memo  = ''     , fd_selt_state   = '{$liststate}' ,  \n                   fd_selt_cwspdate  = now() \n            where fd_selt_id = '{$listid}' ";
        $db->query($query);
        //修改单据资料
        //更新订单状态
        $query = "update web_order set fd_order_state = '7',fd_order_gzdate = now()  where fd_order_id = '{$weborderid}'";
        $dberp->query($query);
        $query = "select * from web_order where fd_order_id = '{$weborderid}'";
        $dberp->query($query);
        if ($dberp->nf()) {
            $dberp->next_record();
            $memeberid = $dberp->f(fd_order_memeberid);
            $gdr = $dberp->f(fd_order_ddclr);
            //激活会员卡
            $query = "update tb_organmem set fd_organmem_active = '1'  where fd_organmem_id = '{$memeberid}'";
            $dberp->query($query);
            $query = "update web_salercard  set fd_salercard_opendate = now()  where fd_salercard_memberid  = '{$memeberid}' and fd_salercard_opendate = '0000-00-00'";
            $dberp->query($query);
        }
        $query = "select * from tb_salelist_2010 where fd_selt_id = '{$listid}'";
        $db->query($query);
        if ($db->nf()) {
            $db->next_record();
            $listid_2010 = $db->f(fd_selt_id);
            $listno = $db->f(fd_selt_no);
            //单据编号
            $cusid = $db->f(fd_selt_cusid);
            //客户id号
            $cusno = $db->f(fd_selt_cusno);
            //客户编号
            $cusname = $db->f(fd_selt_cusname);
            //客户名称
            $sendcenterid = $db->f(fd_selt_sdcrid);
            //配送中心id号
            $mscompanyid = $db->f(fd_selt_mscompanyid);
            //所属公司id号
            $memo = $db->f(fd_selt_memo);
            $iswebsale = $db->f(fd_selt_iswebsale);
            $ishavetax = $db->f(fd_selt_ishavetax);
            $ishavetax = $db->f(fd_selt_ishavetax);
            $skfs = $db->f(fd_selt_skfs);
            $jhcldate = $db->f(fd_selt_jhcldate);
            $cwspdate = $db->f(fd_selt_cwspdate);
            $ckchdate = $db->f(fd_selt_ckchdate);
            $ckqrdate = $db->f(fd_selt_ckqrdate);
            $zjlspdate = $db->f(fd_selt_zjlspdate);
            $ldr = $db->f(fd_selt_ldr);
            $historymemo = $db->f(fd_selt_historymemo);
            $shplace = $db->f(fd_selt_shplace);
            $consignee = $db->f(fd_selt_consignee);
            $webpaymoney = $db->f(fd_selt_webpaymoney);
            $weborderid = $db->f(fd_selt_weborderid);
            $weborderno = $db->f(fd_selt_weborderno);
            $date = $db->f(fd_selt_date);
            $trafficmodel = $db->f(fd_selt_trafficmodel);
            $cardid = $db->f(fd_selt_cardid);
            $wlyf = $db->f(fd_selt_wlyf);
            //物流运费
            $wlzftype = $db->f(fd_selt_wlzftype);
            //物流运费支付类型
            $ysgsid = $db->f(fd_selt_ysgsid);
        }
        $query = "select fd_selt_id from tb_salelist where fd_selt_salelistid = '{$listid}' and fd_selt_no = '{$listno}'";
        $db->query($query);
        if ($db->nf()) {
            $db->next_record();
            $listid = $db->f(fd_selt_id);
        } else {
            $query = "insert into tb_salelist (\n              fd_selt_no           , fd_selt_cusid              , fd_selt_cusno       ,\n              fd_selt_cusname      , fd_selt_accountid          , \n              fd_selt_sdcrid       , fd_selt_mscompanyid        , fd_selt_date        ,\n              fd_selt_organid      , fd_selt_datetime           , fd_selt_memo        , \n              fd_selt_iswebsale    , fd_selt_ishavetax          , fd_selt_trafficmodel, \n              fd_selt_skfs         , fd_selt_jhcldate           , fd_selt_zjlspdate   , \n              fd_selt_cwspdate     , fd_selt_ckchdate           , fd_selt_ckqrdate    ,\n              fd_selt_ldr          , fd_selt_historymemo        , fd_selt_state       ,\n              fd_selt_consignee    , fd_selt_shplace            , fd_selt_webpaymoney ,\n              fd_selt_weborderid   , fd_selt_weborderno         , fd_selt_salelistid  ,\n              fd_selt_cardid       , fd_selt_wlyf               , fd_selt_wlzftype    ,\n              fd_selt_ysgsid \n              )values( \n              '{$listno}'            , '{$cusid}'                   , '{$cusno}'            ,\n              '{$cusname}'           , '{$accountid}'               ,\n              '{$sendcenterid}'      , '{$mscompanyid}'             , '{$date}'             ,\n              '1'                  , now()                      , '{$memo}'             , \n              '{$iswebsale}'         , '{$ishavetax}'               , '{$trafficmodel}'     , \n              '{$skfs}'              ,'{$jhcldate}'                 , '{$zjlspdate}'        , \n              '{$cwspdate}'          , '{$ckchdate}'                , '{$ckqrdate}'         ,\n              '{$ldr}'               , '{$historymemo}'             , '1'                 ,    \n              '{$consignee}'         , '{$shplace}'                 , '{$webpaymoney}'      ,                     \n              '{$weborderid}'        , '{$weborderno}'              , '{$listid}'           ,\n              '{$cardid}'            , '{$wlyf}'                    , '{$wlzftype}'         ,\n              '{$ysgsid}'\n              )";
            $db->query($query);
            $listid = $db->insert_id();
            //取出刚插入的记录的主关键值的id
            //------------------------------插入采购单--------------------------------
            $cg_listid = 0;
            $query = "select fd_cus_linkorganid from tb_customer where fd_cus_id = '{$cusid}' ";
            $db1->query($query);
            if ($db1->nf()) {
                $db1->next_record();
                $linkorganid = $db1->f(fd_cus_linkorganid);
                $msc_name = "";
                $query = "select fd_msc_name from tb_mscompany where fd_msc_id = '{$mscompanyid}' ";
                $db1->query($query);
                if ($db1->nf()) {
                    $db1->next_record();
                    $msc_name = $db1->f(fd_msc_name);
                }
                $suppid = "";
                $suppno = "";
                $suppname = "";
                $query = "select fd_supp_id , fd_supp_no  from tb_supplier \n    \t          where fd_supp_allname = '{$msc_name}' and fd_supp_organid = '{$linkorganid}' ";
                $db1->query($query);
                if ($db1->nf()) {
                    $db1->next_record();
                    $suppid = $db1->f(fd_supp_id);
                    $suppno = $db1->f(fd_supp_no);
                    $suppname = $msc_name;
                } else {
                    $suppno = changepinyin($msc_name) . "-" . $linkorganid;
                    $suppname = $msc_name;
                    $query = "insert into tb_supplier(\n    \t            fd_supp_no , fd_supp_allname  , fd_supp_organid\n    \t            )values(\n    \t            '{$suppno}'  , '{$suppname}'      , '{$linkorganid}'\n    \t            )";
                    $db1->query($query);
                    $suppid = $db1->insert_id();
                    //取出刚插入的记录的主关键值的id
                }
                $cg_memo_z = "网购销售单自动生成到分行的进货单";
                $cg_listno = listnumber_update(1);
                //保存单据
                $query = "insert into tb_stock(\n                fd_stock_no          ,   fd_stock_suppid        , fd_stock_suppno           ,\n                fd_stock_suppname    ,   fd_stock_organid       , fd_stock_date             , \n                fd_stock_memo        ,   fd_stock_staid         , fd_stock_sdcrid           ,\n                fd_stock_dealwithman ,   fd_stock_dyj           , fd_stock_paymentdate      \n                {$fieldsql}\n                )values(\n                '{$cg_listno}'        ,   '{$suppid}'          , '{$suppno}'             ,\n                '{$suppname}'         ,   '{$linkorganid}'     , now()                 ,\n                '{$cg_memo_z}'        ,   '0'                , '0'                   ,\n                ''                  ,   '0'                , now()                 \n                )";
                $db->query($query);
                //插入单据资料
                $cg_listid = $db->insert_id();
                //取出刚插入的记录的主关键值的id
            }
        }
        //更新客户的往来单据时间
        $query = "update tb_customer set fd_cus_newdatetime = now(),fd_cus_newlistid = '{$listid}',\n            fd_cus_newlisttype = '1'\n            where fd_cus_id = '{$cusid}'";
        $db->query($query);
        //插入销售细节表的商品数据
        $query = "select * from tb_salelistdetail_2010 where fd_stdetail_seltid = '{$listid_2010}' ";
        $db->query($query);
        if ($db->nf()) {
            while ($db->next_record()) {
                $v_stdetailid = $db->f(fd_stdetail_id);
                $v_storageid = $db->f(fd_stdetail_storageid);
                $v_commid = $db->f(fd_stdetail_commid);
                $v_commbar = $db->f(fd_stdetail_commbar);
                $v_commname = $db->f(fd_stdetail_commname);
                $v_unit = $db->f(fd_stdetail_unit);
                $v_quantity = $db->f(fd_stdetail_quantity);
                $v_price = $db->f(fd_stdetail_price);
                $v_memo = $db->f(fd_stdetail_memo);
                $query = "select * from tb_salelistdetail where fd_stdetail_stdetailid = '{$v_stdetailid}' and fd_stdetail_seltid = '{$listid}' ";
                $db1->query($query);
                if ($db1->nf()) {
                } else {
                    $query = "insert into tb_salelistdetail (\n  \t\t               fd_stdetail_seltid        , fd_stdetail_storageid , fd_stdetail_commid  , \n  \t\t               fd_stdetail_commbar       , fd_stdetail_commname  , fd_stdetail_unit    ,\n  \t\t               fd_stdetail_quantity      , fd_stdetail_price     , fd_stdetail_memo          \n  \t\t               )values(\n  \t\t               '{$listid}'                 , '{$v_storageid}'        , '{$v_commid}'         ,\n  \t\t               '{$v_commbar}'              , '{$v_commname}'         , '{$v_unit}'           ,\n  \t\t               '{$v_quantity}'             , '{$v_price}'            , '{$v_memo}'             \n  \t\t               )";
                    $db1->query($query);
                    if ($cg_listid > 0) {
                        $query = "insert into tb_stockdetail(\n  \t                     fd_skdetail_stockid  ,  fd_skdetail_commid  ,  fd_skdetail_storageid ,\n  \t                     fd_skdetail_commname ,  fd_skdetail_commbar ,  fd_skdetail_unit      ,\n  \t                     fd_skdetail_quantity ,  fd_skdetail_price   ,  fd_skdetail_memo    \n  \t                     )values(\n  \t                     '{$cg_listid}'         ,  '{$v_commid}'         ,  '0'                   ,\n  \t                     '{$v_commname}'        ,  '{$v_commbar}'        ,  '{$v_unit}'             ,\n  \t                     '{$v_quantity}'        ,  '{$v_price}'          ,  '{$v_memo}'          \n  \t                     )";
                        $db1->query($query);
                        //插入细节表 数据
                    }
                }
            }
        }
        $allmoney = 0;
        $alldunquantity = 0;
        $alldunmoney = 0;
        $allstoragecost = 0;
        $query = "select * from tb_salelistdetail \n            left join tb_produre on fd_produre_id = fd_stdetail_commid\n            where fd_stdetail_seltid = '{$listid}'";
        $db->query($query);
        if ($db->nf()) {
            while ($db->next_record()) {
                $commid = $db->f(fd_stdetail_commid);
                $quantity = $db->f(fd_stdetail_quantity);
                $tmpsbdetailid = $db->f(fd_stdetail_id);
                $price = $db->f(fd_stdetail_price);
                //单价
                $tmpunit = $db->f(fd_stdetail_unit);
                $tmpcost = $db->f(fd_stdetail_tmpcost);
                $tmpralation = $db->f(fd_produre_relation3);
                //对应关系3
                $storageid = $db->f(fd_stdetail_storageid);
                //仓库ID
                $dunquantity = changekg($tmpralation, $tmpunit, $quantity);
                //吨数量
                $alldunquantity += $dunquantity;
                if (empty($sendcenterid)) {
                    $sendcenterid = 0;
                    //配送中心id
                }
                //查找库存是否有数量
                $flagquantity = 0;
                $query = "select * from tb_stockquantity where fd_skqy_organid = '1' \n                   and fd_skqy_commid = '{$commid}' and fd_skqy_sdcrid = '{$sendcenterid}'";
                $db1->query($query);
                if ($db1->nf()) {
                    while ($db1->next_record()) {
                        if ($db1->f(fd_skqy_quantity) != 0) {
                            $flagquantity = 1;
                        }
                    }
                }
                //查找是否有库存成本价
                $query = "select * from tb_storagecost where fd_sect_organid = '1'\n  \t\t             and fd_sect_commid = '{$commid}' and fd_sect_sdcrid = '{$sendcenterid}'";
                $db1->query($query);
                if ($db1->nf()) {
                    $db1->next_record();
                    $storagecost = $db1->f(fd_sect_cost);
                    if ($storagecost == 0 and $flagquantity == 0) {
                        //如果库存单价为0时,就修改库存单价
                        $query = "update tb_storagecost set fd_sect_cost = '{$tmpcost}'\n                       where fd_sect_organid = '1'  and fd_sect_sdcrid = '{$sendcenterid}'\n                       and fd_sect_commid = '{$commid}'";
                        $db1->query($query);
                    }
                } else {
                    //如果没有库存成本记录
                    $storagecost = 0;
                    if ($flagquantity == 0) {
                        $query = "insert into tb_storagecost(\n                       fd_sect_cost    ,  fd_sect_commid , fd_sect_organid ,\n                       fd_sect_sdcrid  \n                       )values(\n                       '{$tmpcost}'      ,  '{$commid}'      , '1'  ,\n                       '{$sendcenterid}'\n                       )";
                        $db1->query($query);
                    }
                }
                if ($storagecost == 0 and $flagquantity == 0) {
                    $storagecost = $tmpcost;
                }
                //修改仓库的数量和成本价
                updatestorage($commid, $quantity, $storagecost, $storageid, 1, $sendcenterid, 1);
                //0代表正、1代表负
                $query = "update tb_salelistdetail set fd_stdetail_cost = '{$storagecost}'\n                   where fd_stdetail_id = '{$tmpsbdetailid}'  ";
                $db1->query($query);
                //修改商品的库存成本价
                $allstoragecost += $storagecost * $quantity;
                //销售成本价
                //商品流水帐
                $cogememo = "商品销售减少";
                $cogelisttype = "3";
                $cogetype = 1;
                //0为增加 , 1为减少
                commglide($storageid, $commid, $quantity, $cogememo, $cogelisttype, $gdr, $listid, $listno, $cogetype, $date);
                $allmoney += $quantity * $price;
                //销售总额
                /*
                  		   //记录该商品卖给该客户的最近销售价
                  		   $query = "select * from tb_savesalepirce where fd_ssp_cusid = '$cusid' and fd_ssp_commid = '$commid'";
                  		   $db1->query($query);
                  		   if($db1->nf()){
                  		   	$query = "update tb_savesalepirce set fd_ssp_price = '$price' 
                  		   	          where fd_ssp_cusid = '$cusid' and fd_ssp_commid = '$commid'";
                  		   	$db1->query($query);
                  		   }else{
                  		     $query = "insert into tb_savesalepirce(
                  		               fd_ssp_cusid  , fd_ssp_commid  , fd_ssp_price
                  		               )values(
                  		               '$cusid'   ,  '$commid'  , '$price'
                  		               )";
                  		     $db1->query($query);
                }
                */
            }
        }
        /*
        //查询即时的应收应付款
        if($organtype==1){
        	$ysyf_sqlwhere = " and fd_ysyfm_mscompanyid = '$mscompanyid'";
        }else{
          $ysyf_sqlwhere = "";
        }
        
        
        $query = "select * from tb_ysyfmoney where fd_ysyfm_organid = '1'
                  and fd_ysyfm_type = '1' and fd_ysyfm_companyid = '$cusid'
                  $ysyf_sqlwhere ";
        $db->query($query);
        if($db->nf()){
        	$db->next_record();
          $nowysyfmoney = $db->f(fd_ysyfm_money);
        }
        */
        //修改应收金额
        if ($wlzftype == 2) {
            $allmoney = $allmoney + $wlyf;
        }
        $allysmoney = $allmoney;
        //生成总部往来对帐单
        $ctatmemo = "应收" . $cusname . "客户" . $allysmoney . "元";
        $cactlisttype = "3";
        $addmoney = $allmoney;
        $lessenmoney = $paymoney;
        zbcurrentaccount(1, $cusid, $addmoney, $lessenmoney, $ctatmemo, $cactlisttype, $gdr, $listid, $listno, $date, $sendcenterid, $mscompanyid);
        if ($allysmoney != 0) {
            changemoney(1, $cusid, $allysmoney, 0, 1, $sendcenterid, $mscompanyid, $organtype);
            //第四位0代表正,1代表负数
        }
        /*
        //读取客户应收款
        $query = "select * from tb_ysyfmoney 
                   where fd_ysyfm_type =1 and fd_ysyfm_companyid = '$cusid'";
        $db->query($query);
        if($db->nf()){
          while($db->next_record()){
               $yfk += $db->f(fd_ysyfm_money)+0;      
          }  
        }
        	     
        //-------------------------------------------------------
        if($allysmoney>=0){  //判断应收款是否增加或者减少。
        	 if($nowysyfmoney>=0){   //如果往来单位欠我们的款,就直接在应收款科目上增加应收的金额
        	 	  //------------------插入应收款类别科目--------------------------
              $listtype = "3";    //单据类型
              $flstno = "105-".$organno;
              updatesubject($listtype , $listid , $flstno,$allysmoney,0 , 1);  //0代表正,1代表负数 	
        	 }else{ //如果欠往来单位的
        	    $tmpnowysyfmoney = -$nowysyfmoney;
              $discrepantmoeny = $allysmoney - $tmpnowysyfmoney;
              if($discrepantmoeny>0){  //如果应收金额比现在的应付款还大,那就应收款科目增加超出部分金额
              	 $listtype = "3";    //单据类型
                 $flstno = "105-".$organno;
              	 updatesubject($listtype , $listid , $flstno , $discrepantmoeny,0 , 1);  //0代表正,1代表负数
              	  
              	 $listtype = "3";    //单据类型
                 $flstno = "201-".$organno;
                 updatesubject($listtype , $listid , $flstno , $tmpnowysyfmoney,1 , 1);  //0代表正,1代表负数
              }else{  //如果应付款比单据的金额还大,那应付款科目直接减少。
                $listtype = "3";    //单据类型
                $flstno = "201-".$organno;
                updatesubject($listtype , $listid , $flstno , $allysmoney,1 , 1);  //0代表正,1代表负数
             }
        	 }
        }else{
           //多出来的款项目,做成应收款。
           $i_yfmoney = $paymoney - $allmoney ;
           $discrepantmoeny = $i_yfmoney - $nowysyfmoney;
           if($discrepantmoeny>0){  //如果收款金额比应收款的金额还大,那就把超出部分做应付款。
           	 if($nowysyfmoney>=0){  //如果之前应收该往来单位,那就应收款科目就平掉该往来单位的应收款,剩余的部分做到应付款科目里
           	 	  //------------------插入应付款科目--------------------------
                $listtype = "3";    //单据类型
                $flstno = "201-".$organno;
                updatesubject($listtype , $listid , $flstno , $discrepantmoeny,0 , 1);  //0代表正,1代表负数
                
                //------------------插入应收款科目--------------------------
                $listtype = "3";    //单据类型
                $flstno = "105-".$organno;
           	    updatesubject($listtype , $listid , $flstno , $nowysyfmoney,1 , 1);  //0代表正,1代表负数
           	 }else{  //如果之前是应付该往来单位的,应付款科目就增加收取的金额。
           	    //------------------插入应付款科目--------------------------
                $listtype = "3";    //单据类型
                $flstno = "201-".$organno;
                updatesubject($listtype , $listid , $flstno , $i_yfmoney,0 , 1);  //0代表正,1代表负数
           	 }
           	 
           }else{
              //------------------插入应收款科目--------------------------
             $listtype = "3";    //单据类型
             $flstno = "105-".$organno;
           	 updatesubject($listtype , $listid , $flstno , $i_yfmoney,1 , 1);  //0代表正,1代表负数
           }
        }//--------------------------------------------------
         	  
        	  
        //------------------插入库存商品类别科目--------------------------
        $listtype = "3";    //单据类型
        $flstno = "101-".$organno;
        updatesubject($listtype , $listid , $flstno,$allstoragecost,1 , 1);  //0代表正,1代表负数
        */
        //------------------插入销售收入类别科目--------------------------
        $listtype = "3";
        //单据类型
        $flstno = "301-" . $organno;
        updatesubject($listtype, $listid, $flstno, $allnoyfmoney, 0, 1);
        //0代表正,1代表负数
        //------------------插入销售成本类别科目--------------------------
        $listtype = "3";
        //单据类型
        $flstno = "401-" . $organno;
        updatesubject($listtype, $listid, $flstno, $allstoragecost, 0, 1);
        //0代表正,1代表负数
        $query = "update tb_salelist set fd_selt_allmoney = '{$allmoney}'  , fd_selt_allcost = '{$allstoragecost}'  ,\n            fd_selt_alldunshu = '{$alldunquantity}'   , fd_selt_isch = 1 , fd_selt_chdate = now()                 \n            where fd_selt_id = '{$listid}'";
        $db->query($query);
        //修改单据金额
        $query = "update tb_customer set fd_cus_iswebwl = 1 where fd_cus_id = '{$cusid}'";
        $db->query($query);
        //更新订单状态
        $query = "update web_order set fd_order_alldunshu = '{$alldunquantity}',fd_order_allmoney= '{$allmoney}',  \n            fd_order_allcost = '{$allstoragecost}' ,fd_order_state = '7'\n            where fd_order_id = '{$weborderid}'";
        $dberp->query($query);
        $query = "select fd_order_memeberid from web_order where fd_order_id = '{$weborderid}'";
        $dberp->query($query);
        if ($dberp->nf()) {
            $dberp->next_record();
            $memid = $dberp->f(fd_order_memeberid);
        }
        $query = "select max(fd_order_date) as lastbuy,sum(fd_order_allmoney) as allmoney from web_order where (fd_order_state = 6 or fd_order_state = 7) and fd_order_zf = 0 and fd_order_memeberid = '{$memid}' group by fd_order_memeberid";
        $dberp->query($query);
        if ($dberp->nf()) {
            $dberp->next_record();
            $lastbuy = $dberp->f(lastbuy);
            $allmoney = $dberp->f(allmoney);
            $query = "update tb_organmem set fd_organmem_lastsaletime = '{$lastbuy}' , fd_organmem_allmoney = '{$allmoney}' where fd_organmem_id = '{$memid}'";
            $dberp->query($query);
        }
        //更新抢注会员会员卡
        $query = "select * from tb_organmem where fd_organmem_id = '{$memid}'";
        $dberp->query($query);
        $dberp->next_record();
        $getstate = $dberp->f(fd_organmem_getstate);
        $getsalerid = $dberp->f(fd_organmem_getsalerid);
        if ($getstate == 1 and $getsalerid > 0) {
            //检测是否同一网导
            $query = "select * from tb_organmem\n left join web_salercard on fd_salercard_id = fd_organmem_mcardid\n where fd_organmem_id = '{$memid}' and fd_salercard_salerid = '{$getsalerid}'\n ";
            $dberp->query($query);
            if ($dberp->nf() == 0) {
                //选取会员卡
                $query = "select* from web_salercard where fd_salercard_salerid = '{$getsalerid}' and fd_salercard_state =1 and fd_salercard_memberid =0 and fd_salercard_zf =0 limit 0,1";
                $dberp->query($query);
                if ($dberp->nf()) {
                    $dberp->next_record();
                    $mcardid = $dberp->f(fd_salercard_id);
                    //绑定会员卡
                    $query = "update tb_organmem set fd_organmem_mcardid = '{$mcardid}',fd_organmem_getstate=0,fd_organmem_getsalerid=0,fd_organmem_getmemdate='' where fd_organmem_id = '{$memid}'";
                    $dberp->query($query);
                    $query = "update web_salercard set fd_salercard_memberid = '{$memid}',fd_salercard_opendate = now() where fd_salercard_id = '{$mcardid}'";
                    $dberp->query($query);
                    $query = "update tb_salelist set fd_selt_cardid = '{$mcardid}'      \n            where fd_selt_id = '{$listid}'";
                    $db->query($query);
                    //清除抢注资料
                    $query = "delete from  web_getmemcd where fd_getmemcd_salerid = '{$getsalerid}' and fd_getmemcd_memid = '{$memid}'";
                    $dberp->query($query);
                }
            }
        }
        /*
        if($type == "wy"){
          $gotourl = "http://www.ms56.net/mssale/order_zszfcg.php?orderid=".$weborderid;
        }else{
          $gotourl = "http://www.ms56.net/mssale/admin/order/tb_ordercl.php";
        }  
        echo "<script>location='".$gotourl."'</script>";
        */
        //Header("Location: $gotourl");
    }
}