Exemplo n.º 1
0
$dberp = new DB_erp();
$sdcrid = 1;
$query = "select sum(fd_orderdetail_quantity) as quantity,fd_orderdetail_icommid,fd_orderdetail_icommbar,fd_orderdetail_icommname,\n           fd_orderdetail_fqmoney,fd_orderdetail_price,fd_produre_relation3,fd_orderdetail_storageid,fd_orderdetail_productid\n           from web_orderdetail \n           left join tb_produre on fd_orderdetail_icommid = fd_produre_id\n           where fd_orderdetail_orderid = '4615'\n           group by fd_orderdetail_icommid\n          ";
$db->query($query);
if ($db->nf()) {
    while ($db->next_record()) {
        $quantity = $db->f(quantity);
        $commid = $db->f(fd_orderdetail_icommid);
        $commbar = $db->f(fd_orderdetail_icommbar);
        $commname = $db->f(fd_orderdetail_icommname);
        $fqmoney = $db->f(fd_orderdetail_fqmoney);
        $price = $db->f(fd_orderdetail_price);
        $ocommid = $db->f(fd_orderdetail_productid);
        $relation3 = $db->f(fd_produre_relation3);
        $storageid = $db->f(fd_orderdetail_storageid);
        $dunshu = changekg2($relation3, '令', $quantity);
        $money = ($price + $fqmoney) * $dunshu;
        $price = round($money / $quantity, 3);
        //判断成本价
        $query = "select * from tb_storagecost \n  \t             where fd_sect_commid = '{$commid}' and fd_sect_organid = '1' and fd_sect_sdcrid = '{$sdcrid}'";
        echo $query . "<br>";
        $dberp->query($query);
        if (!$dberp->nf()) {
            $query = "select * from tb_storagecost \n  \t               where fd_sect_commid = '{$ocommid}' and fd_sect_organid = '1' and fd_sect_sdcrid = '{$sdcrid}'";
            $dberp->query($query);
            if ($dberp->nf()) {
                $dberp->next_record();
                $ocost = $dberp->f(fd_sect_cost);
                $costmoney = ($ocost + $fqmoney) * $dunshu;
                $cost = round($costmoney / $quantity, 3);
                $query = "INSERT INTO tb_storagecost (\n                   fd_sect_organid      , fd_sect_sdcrid  , fd_sect_commid   ,\n                   fd_sect_cost   \n                   )VALUES (\n                   '1'                  , '{$sdcrid}'       , '{$commid}'        , \n                   '{$cost}'         \n                   )";
function order_creat_salelist_fq($orderid)
{
    $db = new DB_test();
    $db2 = new DB_test();
    $dberp = new DB_erp();
    //读取订单
    $query = "select fd_order_id,fd_order_sdcrid,fd_order_isfp,fd_order_memo,fd_order_paymoney,fd_order_zspaymoney,\n\t                   fd_organmem_cusid,fd_order_receiveadderss,fd_provinces_name,fd_city_name,fd_county_name,fd_order_shman,\n\t                   fd_order_ystype,fd_order_no,fd_organmem_mcardid,fd_order_isfq,fd_order_wlfy,fd_order_wlzftype,fd_order_mobilephone,\n\t                   fd_order_wlzftype,fd_order_ysgsid,fd_order_allmoney,fd_order_mscid\n\t            from web_order \n\t            left join tb_organmem on fd_organmem_id = fd_order_memeberid\n\t            left join tb_provinces on fd_order_province = fd_provinces_code\n\t            left join tb_city on fd_order_city = fd_city_code\n\t            left join tb_county on fd_order_county = fd_county_code\n\t            where fd_order_id = '{$orderid}'";
    $db->query($query);
    if ($db->nf()) {
        $db->next_record();
        $sdcrid = $db->f(fd_order_sdcrid);
        $ishp = $db->f(fd_order_isfp);
        $memo = $db->f(fd_order_memo);
        $paymoney = $db->f(fd_order_paymoney);
        $zspaymoney = $db->f(fd_order_zspaymoney);
        $cusid = $db->f(fd_organmem_cusid);
        $receiveadderss = $db->f(fd_order_receiveadderss);
        $province = $db->f(fd_provinces_name);
        $city = $db->f(fd_city_name);
        $county = $db->f(fd_county_name);
        $consignee = $db->f(fd_order_receiver);
        $csstate = $db->f(fd_order_ystype);
        $orderno = $db->f(fd_order_no);
        $cardid = $db->f(fd_organmem_mcardid);
        $isfq = $db->f(fd_order_isfq);
        $wlyf = $db->f(fd_order_wlfy);
        $wlzftype = $db->f(fd_order_wlzftype);
        $mobilephone = $db->f(fd_order_mobilephone);
        $mscid = $db->f(fd_order_mscid);
        $webpaymoney = $paymoney + $zspaymoney;
        if ($ishp == 1) {
            $ishavetax = 1;
        } else {
            $ishavetax = 2;
        }
        //收货地址
        $shplace = $province . $city . $county . $receiveadderss;
        if ($mscid > 0) {
            $mscompanyid = $mscid;
        } else {
            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;
                            }
                        }
                    }
                }
            }
        }
        if ($csstate == 1) {
            //代办运输
            $trafficmodel = 3;
        } else {
            $trafficmodel = 2;
        }
        //插入销售单
        $query = "select * from tb_customer where fd_cus_id = '{$cusid}'";
        $dberp->query($query);
        if ($dberp->nf()) {
            $dberp->next_record();
            $cusno = $dberp->f(fd_cus_no);
            $cusname = $dberp->f(fd_cus_allname);
        }
        $query = "select * from tb_salelist_2010 where fd_selt_weborderid = '{$orderid}'";
        $dberp->query($query);
        if (!$dberp->nf()) {
            $listno = listnumber_update();
            $query = "insert into tb_salelist_2010(\n\t                fd_selt_no          ,   fd_selt_cusid        , fd_selt_cusno      ,\n\t                fd_selt_cusname     ,   fd_selt_organid      , fd_selt_date       , \n\t                fd_selt_memo        ,   fd_selt_sdcrid       , fd_selt_iswebsale  ,\n\t                fd_selt_ishavetax   ,   fd_selt_trafficmodel , fd_selt_consignee  ,   \n\t                fd_selt_shplace     ,   fd_selt_mscompanyid  , fd_selt_skfs       ,\n\t                fd_selt_state       ,   fd_selt_webpaymoney  , fd_selt_weborderid ,\n\t                fd_selt_weborderno  ,   fd_selt_cardid       , fd_selt_wlyf       ,\n\t                fd_selt_wlzftype    ,   fd_selt_shphone      , fd_selt_ysgsid   \t               \n\t                )values(\n\t                '{$listno}'           ,   '{$cusid}'             , '{$cusno}'           ,\n\t                '{$cusname}'          ,   '1'                  , now()              ,\n\t                '{$memo}'             ,   '{$sdcrid}'            , '1'                ,\n\t                '{$ishavetax}'        ,   '{$trafficmodel}'      , '{$consignee}'       ,\n\t                '{$shplace}'          ,   '{$mscompanyid}'       , '1'                ,\n\t                '92'                ,   '{$webpaymoney}'       , '{$orderid}'         ,\n\t                '{$orderno}'          ,   '{$cardid}'            , '{$wlyf}'            ,\n\t                '{$wlzftype}'         ,   '{$mobilephone}'       , '{$ysgsid}'\n\t                )";
            $dberp->query($query);
            $listid = $dberp->insert_id();
            $query = "update web_order set fd_order_seltid = '{$listid}',fd_order_seltdate=now()  where fd_order_id = '{$orderid}'";
            $db->query($query);
            $query = "select sum(fd_orderdetail_quantity) as quantity,fd_orderdetail_icommid,fd_orderdetail_icommbar,fd_orderdetail_icommname,\n\t                 fd_orderdetail_fqmoney,fd_orderdetail_price,fd_produre_relation3,fd_orderdetail_storageid,fd_orderdetail_productid\n\t                 from web_orderdetail \n\t                 left join tb_produre on fd_orderdetail_icommid = fd_produre_id\n\t                 where fd_orderdetail_orderid = '{$orderid}'\n\t                 group by fd_orderdetail_icommid\n\t                ";
            $db->query($query);
            if ($db->nf()) {
                while ($db->next_record()) {
                    $quantity = $db->f(quantity);
                    $commid = $db->f(fd_orderdetail_icommid);
                    $commbar = $db->f(fd_orderdetail_icommbar);
                    $commname = $db->f(fd_orderdetail_icommname);
                    $fqmoney = $db->f(fd_orderdetail_fqmoney);
                    $price = $db->f(fd_orderdetail_price);
                    $ocommid = $db->f(fd_orderdetail_productid);
                    $relation3 = $db->f(fd_produre_relation3);
                    $storageid = $db->f(fd_orderdetail_storageid);
                    $dunshu = changekg2($relation3, '令', $quantity);
                    $money = ($price + $fqmoney) * $dunshu;
                    $price = round($money / $quantity, 3);
                    //判断成本价
                    $query = "select * from tb_storagecost \n\t        \t             where fd_sect_commid = '{$commid}' and fd_sect_organid = '1' and fd_sect_sdcrid = '{$sdcrid}'";
                    $dberp->query($query);
                    if (!$dberp->nf()) {
                        $query = "select * from tb_storagecost \n\t        \t               where fd_sect_commid = '{$ocommid}' and fd_sect_organid = '1' and fd_sect_sdcrid = '{$sdcrid}'";
                        $dberp->query($query);
                        if ($dberp->nf()) {
                            $dberp->next_record();
                            $ocost = $dberp->f(fd_sect_cost);
                            $costmoney = ($ocost + $fqmoney) * $dunshu;
                            $cost = round($costmoney / $quantity, 3);
                            $query = "INSERT INTO tb_storagecost (\n \t                         fd_sect_organid      , fd_sect_sdcrid  , fd_sect_commid   ,\n \t                         fd_sect_cost   \n                           )VALUES (\n                           '1'                  , '{$sdcrid}'       , '{$commid}'        , \n                           '{$cost}'         \n                           )";
                            $dberp->query($query);
                        }
                    }
                    $query = "INSERT INTO tb_salelistdetail_2010(\n \t                     fd_stdetail_seltid     , fd_stdetail_commid  , fd_stdetail_commname   ,\n \t                     fd_stdetail_commbar    , fd_stdetail_unit    , fd_stdetail_quantity   , \n \t                     fd_stdetail_price      , fd_stdetail_storageid      \n                       )VALUES (\n                       '{$listid}'              , '{$commid}'           , '{$commname}'            , \n                       '{$commbar}'             , '令'                , '{$quantity}'            , \n                       '{$price}'               , '{$storageid}'       \n                       )";
                    $dberp->query($query);
                }
            }
            wgsalegz($listid);
            //$gotourl = "http://www.papersystem.cn/ms2011/sale/up_wgsalegz.php?listid=".$listid;
            //echo "<script>location='".$gotourl."'</script>";
        }
    }
}