function updatesubject($listtype, $listid, $flstno, $money, $type, $organid) { $db = new DB_erp(); if ($money != 0) { if ($type == 0) { $endmoney = $money; } else { $endmoney = -$money; } $query = "select * from tb_fiscalsubject where fd_flst_no = '{$flstno}' and fd_flst_organid = '{$organid}'"; $db->query($query); if ($db->nf()) { $db->next_record(); $flstname = $db->f(fd_flst_name); $oldnowmoney = $db->f(fd_flst_nowmoney); $oldmonthmoney = $db->f(fd_flst_monthmoney); $newnowmoney = $oldnowmoney + $endmoney; $newmonthmoney = $oldmonthmoney + $endmoney; $query = "update tb_fiscalsubject set \n fd_flst_nowmoney = '{$newnowmoney}' ,\n fd_flst_monthmoney = '{$newmonthmoney}' \n where fd_flst_no = '{$flstno}' and fd_flst_organid = '{$organid}'"; $db->query($query); //修改科目金额 } //查出科目名称 $query = "insert into tb_subjectdetail(\n fd_stdl_listtype , fd_stdl_listid , fd_stdl_flstno ,\n fd_stdl_flstname , fd_stdl_money , fd_stdl_organid\n )values(\n '{$listtype}' , '{$listid}' , '{$flstno}' ,\n '{$flstname}' , '{$endmoney}' , '{$organid}'\n )"; $db->query($query); //插入科目详情 } }
$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 )"; echo $query . "<br>"; $dberp->query($query); } } } } //计算商品数量的吨数 function changekg2($relation3, $unit, $quantity) { switch ($unit) { case "令":
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>"; } } }
function listnumber_update() { $db = new DB_erp(); $listtype = 3; $organid = 1; $organno = 'a001'; $ltctcount = 1; $query = "select * from tb_organlistnocount where fd_olnc_listtype = '{$listtype}' \n\t and fd_olnc_organid = '{$organid}' "; $db->query($query); if ($db->nf()) { $db->next_record(); $ltctcount = $db->f(fd_olnc_count) + 1; $olncid = $db->f(fd_olnc_id); $query = "update tb_organlistnocount set fd_olnc_count = '{$ltctcount}'\n\t where fd_olnc_id = '{$olncid}' "; $db->query($query); } else { $query = "insert into tb_organlistnocount(\n\t fd_olnc_count , fd_olnc_organid , fd_olnc_sdcrid ,\n\t fd_olnc_listtype\n\t )values(\n\t 1 , '{$organid}' , '{$sdcrid}' ,\n\t '{$listtype}'\n\t )"; $db->query($query); } if ($ltctcount < 100000 and $ltctcount >= 10000) { $endltctcount = "0" . $ltctcount; } elseif ($ltctcount < 10000 and $ltctcount >= 1000) { $endltctcount = "00" . $ltctcount; } elseif ($ltctcount < 1000 and $ltctcount >= 100) { $endltctcount = "000" . $ltctcount; } elseif ($ltctcount < 100 and $ltctcount >= 10) { $endltctcount = "0000" . $ltctcount; } elseif ($ltctcount < 10 and $ltctcount >= 1) { $endltctcount = "00000" . $ltctcount; } else { $endltctcount = $ltctcount; } $listno = $organno . "-" . $endltctcount; return $listno; }
function makeqx($loginuser) { global $loginuserqx; $db = new DB_erp(); $menufile = "http://www.papersystem.cn/ms2011/include/menuarryfile.php"; $menuarry = file($menufile); //1001±1±地区设置±ico_main_hr.gif±../basic/tb_area_b.php±0± //1001代号、1为上级代号、地区设置为名称、ico_main_hr.gif为图片 //../basic/tb_area_b.php连接地址、0为是否为最底 $query = "select * from tb_teller \n\t left join tb_usegroup on fd_usegroup_id = fd_tel_usegroupid\n\t where fd_tel_id = '{$loginuser}'"; $db->query($query); if ($db->nf()) { $db->next_record(); $str_quanxian = $db->f(fd_tel_doprg); //该用户所拥有的权限 $str_groupqx = $db->f(fd_usegroup_qx); //所属于组权限 if (!empty($str_groupqx)) { //组权限 $tmp_gorupqx = explode("±", $str_groupqx); for ($i = 0; $i < count($tmp_gorupqx); $i++) { $tmp_zqxfp = explode("@", $tmp_gorupqx[$i]); $zqxfp = $tmp_zqxfp[0]; $arr_qxfp[$zqxfp] = 1; //可执行程序 if (!empty($tmp_zqxfp[1])) { //可执行权限 $str_optqx = explode("^", $tmp_zqxfp[1]); //进一步拆分新增等功能 for ($k = 0; $k < count($str_optqx); $k++) { $tmpoptqx = $str_optqx[$k]; //新增等权限代号 $loginuserqx[$zqxfp][$tmpoptqx] = 1; //可执行权限 } } } } if (!empty($str_quanxian)) { //组权限 $tmp_gorupqx = explode("±", $str_quanxian); for ($i = 0; $i < count($tmp_gorupqx); $i++) { $tmp_zqxfp = explode("@", $tmp_gorupqx[$i]); $zqxfp = $tmp_zqxfp[0]; $arr_qxfp[$zqxfp] = 1; //可执行程序 if (!empty($tmp_zqxfp[1])) { //可执行权限 $str_optqx = explode("^", $tmp_zqxfp[1]); //进一步拆分新增等功能 for ($k = 0; $k < count($str_optqx); $k++) { $tmpoptqx = $str_optqx[$k]; //新增等权限代号 $loginuserqx[$zqxfp][$tmpoptqx] = 1; //可执行权限 } } } } $temp_arrqx = explode("±", $str_quanxian); } for ($i = 0; $i < count($temp_arrqx); $i++) { $tmp_qxfp = explode("@", $temp_arrqx[$i]); $qxfp = $tmp_qxfp[0]; $arr_qxfp[$qxfp] = 1; } //--------------------------------------- for ($i = 0; $i < count($menuarry); $i++) { $temp_arr1 = $menuarry[$i]; $temp_arr2 = explode("±", $temp_arr1); $tmpcode = $temp_arr2[0]; if (empty($temp_arr2[1])) { $arr_prgfcode[$tmpcode][fcode] = 0; } else { $arr_prgfcode[$tmpcode][fcode] = $temp_arr2[1]; } $arr_prgfcode[$tmpcode][isunder] = $temp_arr2[5]; $arr_prgfcode[$tmpcode][level] = $temp_arr2[6]; } //------------------------------------- //找出该有的程序 $arr_tmpqx = muqx($arr_qxfp, $arr_prgfcode); return $arr_tmpqx; }
function up_webkc($sdcrid, $commid) { $db = new DB_erp(); $dberp = new DB_test(); $dberp2 = new DB_test(); $query = "select * from tb_websaleprice \n\t left join tb_produre on fd_produre_id = fd_nbsepe_produreid\n\t where fd_nbsepe_sdcrid = '{$sdcrid}' and fd_nbsepe_produreid = '{$commid}'\n\t "; $dberp->query($query); if ($dberp->nf()) { $dberp->next_record(); $webkcquantity = $dberp->f(fd_nbsepe_kcquantity); $trademarkid = $dberp->f(fd_produre_trademarkid); $catalogid = $dberp->f(fd_produre_catalog); //查询订单 //普通订单 $query = "select sum(fd_orderdetail_quantity) as orderquantity from web_orderdetail\n left join web_order on fd_order_id = fd_orderdetail_orderid \n where fd_order_state != '6' and fd_order_state != '7' and fd_order_zf = 0\n and fd_orderdetail_productid = '{$commid}' and fd_order_isfq = 0 and fd_order_sdcrid = '{$sdcrid}'\n group by fd_orderdetail_productid\n "; $dberp->query($query); if ($dberp->nf()) { $dberp->next_record(); $orderquantity = $dberp->f(orderquantity); } //分切订单 $query = "select fd_orderdetail_quantity,fd_orderdetail_fqlong,fd_orderdetail_fqwidth,fd_produre_relation1,fd_kgweight_name \n\t from web_orderdetail\n left join web_order on fd_order_id = fd_orderdetail_orderid \n left join tb_produre on fd_produre_id = fd_orderdetail_productid \n left join tb_kgweight on fd_kgweight_id = fd_produre_kgweight \n where fd_order_state != '6' and fd_order_state != '7' and fd_order_zf = 0\n and fd_orderdetail_productid = '{$commid}' and fd_order_isfq = 1 and fd_order_sdcrid = '{$sdcrid}'\n group by fd_orderdetail_productid\n "; $dberp->query($query); if ($dberp->nf()) { while ($dberp->next_record()) { $quantity = $dberp->f(fd_orderdetail_quantity); $fqlong = $dberp->f(fd_orderdetail_fqlong); $fqwidth = $dberp->f(fd_orderdetail_fqwidth); $relation1 = $dberp->f(fd_produre_relation1); $kgweight = $dberp->f(fd_kgweight_name); $orderquantity += changekg_fq($kgweight, $fqlong, $fqwidth, '令', $quantity, $relation1); } } $query = "select sum(fd_skqy_quantity) as kcquantity from tb_stockquantity \n\t where fd_skqy_sdcrid = '{$sdcrid}' and fd_skqy_commid = '{$commid}'\n\t group by fd_skqy_commid\n\t "; $db->query($query); if ($db->nf()) { $db->next_record(); $kcquantity = $db->f(kcquantity); } $kcquantity = $kcquantity - $orderquantity + 0; if ($kcquantity > 0) { $query = "update tb_websaleprice set \n\t \t fd_nbsepe_kcquantity = '{$kcquantity}',fd_nbsepe_iskc = '1' ,fd_nbsepe_isshow='1'\n\t \t where fd_nbsepe_sdcrid = '{$sdcrid}' and fd_nbsepe_produreid = '{$commid}'\n\t \t "; $dberp->query($query); } else { if ($webkcquantity != 0) { $query = "update tb_websaleprice set \n\t \t fd_nbsepe_kcquantity = '{$kcquantity}',fd_nbsepe_iskc = '0' ,fd_nbsepe_isshow='0'\n\t \t where fd_nbsepe_sdcrid = '{$sdcrid}' and fd_nbsepe_produreid = '{$commid}'\n\t \t "; $dberp->query($query); //更新组合表 $query = "delete from tb_zhmcpricelist WHERE fd_zhmpl_catalogid = '{$catalogid}' AND fd_zhmpl_trademarkid = '{$trademarkid}'"; $dberp->query($query); $query = "select fd_trademark_id,fd_produre_catalog,fd_kgweight_name,\n fd_kgweight_id,fd_nbsepe_sdcrid\n from tb_kgweight\n left join tb_produre on fd_produre_kgweight = fd_kgweight_id\n left join tb_trademark on fd_trademark_id = fd_produre_trademarkid\n left join tb_websaleprice on fd_produre_id = fd_nbsepe_produreid\n where fd_nbsepe_iskc = 1 and fd_nbsepe_isshow = 1 \n and fd_produre_catalog = '{$catalogid}' AND fd_produre_trademarkid = '{$trademarkid}'\n group by fd_nbsepe_sdcrid,fd_kgweight_id,fd_trademark_id,fd_produre_catalog\n "; $dberp->query($query); if ($dberp->nf()) { while ($dberp->next_record()) { $brandid = $dberp->f(fd_trademark_id); $procaid = $dberp->f(fd_produre_catalog); $sdcrid = $dberp->f(fd_nbsepe_sdcrid); if ($arr_kw[$sdcrid][$brandid][$procaid] == "") { $arr_kw[$sdcrid][$brandid][$procaid] = $dberp->f(fd_kgweight_name); $arr_kwid[$sdcrid][$brandid][$procaid] = $dberp->f(fd_kgweight_id); } else { $arr_kw[$sdcrid][$brandid][$procaid] .= "/" . $dberp->f(fd_kgweight_name); $arr_kwid[$sdcrid][$brandid][$procaid] .= "/" . $dberp->f(fd_kgweight_id); } } } $query = "select fd_trademark_id,fd_produre_catalog,fd_guige_name,fd_guige_id,fd_nbsepe_sdcrid \n from tb_guige \n left join tb_produre on fd_produre_spec = fd_guige_id\n left join tb_trademark on fd_trademark_id = fd_produre_trademarkid\n left join tb_websaleprice on fd_produre_id = fd_nbsepe_produreid\n where fd_nbsepe_iskc = 1 and fd_nbsepe_isshow = 1 \n and fd_produre_catalog = '{$catalogid}' AND fd_produre_trademarkid = '{$trademarkid}' \n group by fd_nbsepe_sdcrid,fd_guige_id,fd_trademark_id,fd_produre_catalog\n "; $dberp->query($query); if ($dberp->nf()) { while ($dberp->next_record()) { $brandid = $dberp->f(fd_trademark_id); $procaid = $dberp->f(fd_produre_catalog); $sdcrid = $dberp->f(fd_nbsepe_sdcrid); if ($arr_gg[$sdcrid][$brandid][$procaid] == "") { $arr_gg[$sdcrid][$brandid][$procaid] = $dberp->f(fd_guige_name); $arr_ggid[$sdcrid][$brandid][$procaid] = $dberp->f(fd_guige_id); } else { $arr_gg[$sdcrid][$brandid][$procaid] .= "/" . $dberp->f(fd_guige_name); $arr_ggid[$sdcrid][$brandid][$procaid] .= "/" . $dberp->f(fd_guige_id); } } } $query = "select fd_nbsepe_sdcrid as sdcrid ,\n fd_trademark_id,\n fd_trademark_name,\n fd_proca_id,\n fd_proca_catname,\n fd_nbsepe_bjunit,\n fd_productlevel_name,\n fd_productlevel_id,\n min(fd_nbsepe_dunprice) as minprice,max(fd_nbsepe_dunprice) as maxprice,\n min(fd_nbsepe_lingprice) as minprice2,max(fd_nbsepe_lingprice) as maxprice2\n from tb_websaleprice \n left join tb_produre on fd_produre_id = fd_nbsepe_produreid and fd_nbsepe_iskc = 1\n left join tb_procatalog on fd_produre_catalog = fd_proca_id\n left join tb_trademark on fd_trademark_id = fd_produre_trademarkid\n left join tb_productlevel on fd_productlevel_id = fd_produre_level \n where fd_nbsepe_lingprice <> 0 and fd_nbsepe_iskc =1 and fd_nbsepe_isshow = 1 and fd_produre_level = 1\n and fd_produre_catalog = '{$catalogid}' AND fd_produre_trademarkid = '{$trademarkid}'\n group by fd_nbsepe_sdcrid,fd_proca_id,fd_trademark_id\n order by fd_proca_catname"; $dberp->query($query); if ($dberp->nf()) { while ($dberp->next_record()) { $sdcrid = $dberp->f(sdcrid); $trademarkid = $dberp->f(fd_trademark_id); $catalogid = $dberp->f(fd_proca_id); $trademark = $dberp->f(fd_trademark_name); $catalog = $dberp->f(fd_proca_catname); $level = $dberp->f(fd_productlevel_name); $levelid = $dberp->f(fd_productlevel_id); $bjunit = $dberp->f(fd_nbsepe_bjunit); if ($bjunit == "吨") { $minprice = round($dberp->f(minprice) * 1.06, 0); $maxprice = round($dberp->f(maxprice) * 1.06, 0); } else { $minprice = round($dberp->f(minprice2) * 1.06, 3); $maxprice = round($dberp->f(maxprice2) * 1.06, 3); } $kgweight = $arr_kw[$sdcrid][$trademarkid][$catalogid]; $kgweightid = $arr_kwid[$sdcrid][$trademarkid][$catalogid]; $guige = $arr_gg[$sdcrid][$trademarkid][$catalogid]; $guigeid = $arr_ggid[$sdcrid][$trademarkid][$catalogid]; if ($catalogid > 0) { $query = "insert into tb_zhmcpricelist(\n \t \t \t\t fd_zhmpl_catalogid , fd_zhmpl_trademarkid , fd_zhmpl_trademark ,\n \t \t \t\t fd_zhmpl_catalog , fd_zhmpl_level ,\n \t \t \t\t fd_zhmpl_levelid , fd_zhmpl_minprice , fd_zhmpl_maxprice ,\n \t \t \t\t fd_zhmpl_bjunit , fd_zhmpl_kgweightid , fd_zhmpl_kgweight ,\n \t\t\t\t \t\t fd_zhmpl_guigeid , fd_zhmpl_guige , fd_zhmpl_sdcrid \n \t \t \t\t )values( \n \t \t \t '{$catalogid}' , '{$trademarkid}' , '{$trademark}' ,\n \t \t \t\t '{$catalog}' , '{$level}' , \n \t \t \t\t '{$levelid}' , '{$minprice}' , '{$maxprice}' ,\n \t \t \t\t '{$bjunit}' , '{$kgweightid}' , '{$kgweight}' ,\n \t\t\t\t \t\t '{$guigeid}' , '{$guige}' , '{$sdcrid}' \n \t \t \t )"; $dberp2->query($query); } } } } } } }
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"); } }