if ($db->nf()) { $db->next_record(); //读取记录数据 $suppid = $db->f(fd_stock_suppid); //客户id $suppno = $db->f(fd_stock_suppno); //客户编号 $suppname = $db->f(fd_stock_suppname); //客户名称 $now = $db->f(fd_stock_date); //录单日期 $memo = $db->f(fd_stock_memo); //备注 $allmoney = $db->f(fd_stock_allmoney); //备注 $listno = listnumber_update(1); //保存单据 $query = "INSERT INTO tb_paycardstock(\n \t fd_stock_no , fd_stock_suppid , fd_stock_suppno ,\n \t fd_stock_suppname , fd_stock_date , fd_stock_allmoney,\n \t fd_stock_memo \n )VALUES (\n '{$listno}' , '{$suppid}' , '{$suppno}' ,\n '{$suppname}' , '{$now}' , '{$allmoney}' ,\n '{$memo}' \n )"; $db->query($query); $oldid = $db->insert_id(); } if (!empty($oldid)) { $query = "select * from tb_paycardstockdetail \n where fd_skdetail_stockid = '{$listid}'"; $db->query($query); if ($db->nf()) { while ($db->next_record()) { $paycardid = $db->f(fd_skdetail_paycardid); //商品ID $proprice = $db->f(fd_skdetail_price); //价格 $quantity = $db->f(fd_skdetail_quantity);
$query = "select * from tb_inmoneylist where fd_inmylt_id = '{$listid}'"; $db->query($query); //提取帐户id号 if ($db->nf()) { $db->next_record(); $accountid = $db->f(fd_inmylt_accountid); $paymoney = $db->f(fd_inmylt_money); $dealwithman = $db->f(fd_inmylt_dealwithman); $cusid = $db->f(fd_inmylt_clientid); $cusno = $db->f(fd_inmylt_clientno); $clienttype = $db->f(fd_inmylt_type); $cusname = $db->f(fd_inmylt_clientname); $staid = $db->f(fd_inmylt_staid); $date = $db->f(fd_inmylt_date); $memo_z = $db->f(fd_inmylt_memo); $listno = listnumber_update(8); //保存单据 $query = "insert into tb_inmoneylist(\n fd_inmylt_no , fd_inmylt_clientid , fd_inmylt_type ,\n fd_inmylt_clientname , fd_inmylt_staid , fd_inmylt_accountid ,\n fd_inmylt_money , fd_inmylt_date , fd_inmylt_memo ,\n fd_inmylt_dealwithman , fd_inmylt_clientno \n )values(\n '{$listno}' , '{$cusid}' , '{$clienttype}' ,\n '{$cusname}' , '{$staid}' , '{$accountid}' ,\n '{$paymoney}' , '{$date}' , '{$memo_z}' ,\n '{$dealwithman}' , '{$cusno}' \n )"; $db1->query($query); //插入付款单 } } $count = 0; $allbalance = 0; //总共余额 if (empty($listid)) { $t->set_file("inmoneylist_view", "inmoneylist_view.html"); $t->set_block("inmoneylist_view", "prolist", "prolists"); $error = "错误:该单据不存在!"; } else { //如果收款单id号不是为空
//读取记录数据 $cusid = $db->f(fd_selt_cusid); //客户id $cusno = $db->f(fd_selt_cusno); //客户编号 $cusname = $db->f(fd_selt_cusname); //客户名称 $now = $db->f(fd_selt_date); //录单日期 $datetime = $db->f(fd_selt_datetime); //录单日期 $memo = $db->f(fd_selt_memo); //备注 $skfs = $db->f(fd_selt_skfs); //收款方式 $listno = listnumber_update(3); //保存单据 $query = "INSERT INTO tb_salelist(\n \t fd_selt_no , fd_selt_cusid , fd_selt_cusno ,\n \t fd_selt_cusname , fd_selt_date ,\n \t fd_selt_memo , fd_selt_allmoney , \n\t\t\t\t\tfd_selt_skfs ,fd_selt_datetime\n )VALUES (\n '{$listno}' , '{$cusid}' , '{$cusno}' ,\n '{$cusname}' , '{$now}' , \n '{$memo}' , '{$paymoney}' , \n '{$skfs}' ,'{$datetime}' \n )"; $db->query($query); $oldid = $db->insert_id(); } if (!empty($oldid)) { $query = "select * from tb_salelistdetail \n where fd_stdetail_seltid = '{$listid}'"; $db->query($query); if ($db->nf()) { while ($db->next_record()) { $proid = $db->f(fd_stdetail_paycardid); //商品ID $proprice = $db->f(fd_stdetail_price); //价格 $query = "INSERT INTO tb_salelistdetail (\n \t fd_stdetail_seltid , fd_stdetail_paycardid , fd_stdetail_price \n )VALUES (\n '{$oldid}' , '{$proid}' , '{$proprice}' \n )";
$paycardnum = count($arr_num); $query = "update tb_paycardstockbackdetail set fd_skdetail_paycardid='{$del_paycardid}', fd_skdetail_quantity='{$paycardnum}' where fd_skdetail_id = '{$delskdetailid}'"; $db->query($query); $query = "update tb_salelist_tmp set fd_tmpsale_paycardid='{$del_paycardid}' where fd_tmpsale_seltid = '{$delskdetailid}' and fd_tmpsale_type='stockback'"; $db->query($query); $query = "update tb_paycard set fd_paycard_state='1' where fd_paycard_id='{$delpaycard}'"; $db->query($query); countallbackpaycard($listid); //统计刷卡器数量,金额 echo "<script>alert('删除成功!');location.href='jxcstockback.php?listid={$listid}';</script>"; break; case "new": //新增数据 if (empty($listid)) { //如果单据id是不存在的 listnumber_update(2); //保存单据 $query = "select * from tb_paycardstockback where fd_stock_no = '{$listno}' "; $db->query($query); if ($db->nf()) { $error = "单据编号已经存在!请查证!"; } else { $query = "insert into tb_paycardstockback(\n\t fd_stock_no , fd_stock_suppid , fd_stock_suppno ,\n\t fd_stock_suppname , fd_stock_date , fd_stock_ldr ,\n\t fd_stock_dealwithman , fd_stock_memo \n\t )values(\n\t '{$listno}' , '{$suppid}' , '{$suppno}' ,\n\t '{$suppname}' , '{$date}' , '{$loginstaname}' ,\n\t '{$dealwithman}' , '{$memo_z}' \n\t )"; $db->query($query); //插入单据资料 $listid = $db->insert_id(); //取出刚插入的记录的主关键值的id } } else { //如果单据id号已经存在 $query = "select * from tb_paycardstockback where fd_stock_no = '{$listno}' and fd_stock_id <> '{$listid}' ";
$db->query($query); //提取帐户id号 if ($db->nf()) { $db->next_record(); $accountid = $db->f(fd_pymylt_accountid); $paymoney = $db->f(fd_pymylt_money); $dealwithman = $db->f(fd_pymylt_dealwithman); $cusid = $db->f(fd_pymylt_clientid); $cusno = $db->f(fd_pymylt_clientno); $clienttype = $db->f(fd_pymylt_type); $cusname = $db->f(fd_pymylt_clientname); $staid = $db->f(fd_pymylt_staid); $date = $db->f(fd_pymylt_date); $memo_z = $db->f(fd_pymylt_memo); $sklinkman = $db->f(fd_pymylt_sklinkman); $listno = 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_accountid ,\n fd_pymylt_money , fd_pymylt_date , fd_pymylt_memo ,\n fd_pymylt_dealwithman , fd_pymylt_clientno , fd_pymylt_sklinkman\n )values(\n '{$listno}' , '{$cusid}' , '{$clienttype}' ,\n '{$cusname}' , '{$staid}' , '{$accountid}' ,\n '{$paymoney}' , '{$date}' , '{$memo_z}' ,\n '{$dealwithman}' , '{$cusno}' , '{$sklinkman}'\n )"; $db1->query($query); //插入付款单 } } $allbalance = 0; //总共余额 if (empty($listid)) { $t->set_file("paymoneylist_view", "paymoneylist_view.html"); $t->set_block("paymoneylist_view", "prolist", "prolists"); $error = "错误:该单据不存在!"; } else { //如果销售单id好不是为空 $action = "edit";
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 order_creat_kslist($listid) { $db = new DB_test(); $db2 = new DB_test(); $dberp = new DB_erp2(); //读取客诉申请 $query = "select * from web_kesu \n\t left join tb_produre on fd_produre_id = fd_ks_commid \n\t left join tb_productlevel on fd_productlevel_id = fd_produre_level \n\t left join tb_kgweight on fd_kgweight_id = fd_produre_kgweight \n\t left join tb_guige on fd_guige_id = fd_produre_spec \n\t left join web_orderdetail on fd_ks_orderdtid = fd_orderdetail_id \n\t left join web_order on fd_order_id = fd_ks_orderid\n\t where fd_ks_id = '{$listid}'"; $db->query($query); if ($db->nf()) { $db->next_record(); $commid = $db->f(fd_ks_commid); $thquantity = $db->f(fd_ks_tuinum); $printsize = $db->f(fd_ks_yincc); $fqsl = $db->f(fd_ks_fenqienum); $shsl = $db->f(fd_ks_sunhao); $printsl = $db->f(fd_ks_yinnum); $memo = $db->f(fd_ks_canzhi); $ksmoney = $db->f(fd_ks_money); $ksyy = $db->f(fd_ks_cause); $zlms = $db->f(fd_ks_ksmemo); $memo = $db->f(fd_ks_memo); $czmoney = $db->f(fd_ks_canzhi); $commname = $db->f(fd_produre_name); $level = $db->f(fd_productlevel_name); $kz = $db->f(fd_kgweight_name); $gg = $db->f(fd_guige_name); $orderid = $db->f(fd_ks_orderid); $price = $db->f(fd_orderdetail_price); $quantity = $db->f(fd_orderdetail_quantity); $sdcrid = $db->f(fd_order_sdcrid); if ($cause == 1) { //印刷不良 $ksyy = "1@@@"; } else { if ($cause == 2) { //纸张表面异常 $ksyy = "6@@@"; } else { if ($cause == 3) { //纸张克数不够 $ksyy = "4@@@"; } else { if ($cause == 4) { //打烂胶布 $ksyy = "5@@@"; } } } } $money = $quantity * $price; $kstype = 2; if ($sdcrid == 1) { $mscid = 1; //广州市明盛物流有限公司 } else { if ($sdcrid == 2) { $mscid = 4; //上海粤琳珠物流有限公司 } else { if ($sdcrid == 3) { $mscid = 13; //廊坊市明盛纸业有限公司 } else { if ($sdcrid == 4) { $mscid = 9; } else { if ($sdcrid == 5) { $mscid = 11; } } } } } $query = "select * from tb_mscompany where fd_msc_id = '{$mscid}'"; $dberp->query($query); if ($dberp->nf()) { $dberp->next_record(); $msclinkman = $dberp->f(fd_msc_phone); } $query = "select * from tb_salelist where fd_selt_weborderid = '{$orderid}'"; $dberp->query($query); if ($dberp->nf()) { $dberp->next_record(); $xsno = $dberp->f(fd_selt_no); $xsdate = $dberp->f(fd_selt_date); $cusid = $dberp->f(fd_selt_cusid); } $listno = listnumber_update(); $query = "insert into tb_kssq(\n\t \t fd_kssq_no , fd_kssq_date , fd_kssq_organid ,\n\t \t fd_kssq_mscid , fd_kssq_msclinkman , fd_kssq_cusid ,\n\t \t fd_kssq_commid , fd_kssq_commname , fd_kssq_level ,\n\t \t fd_kssq_kz , fd_kssq_gg , fd_kssq_xsno ,\n\t \t fd_kssq_xsdate , fd_kssq_price , fd_kssq_quantity ,\n\t \t fd_kssq_money , fd_kssq_thquantity , fd_kssq_ksmoney ,\n\t \t fd_kssq_czmoney , fd_kssq_ksyy , fd_kssq_zlms ,\n\t \t fd_kssq_memo , fd_kssq_kstype , fd_kssq_printsize , \n\t \t fd_kssq_fqsl , fd_kssq_printsl , fd_kssq_shsl ,\n\t \t fd_kssq_state , fd_kssq_webksid \n\t \t )values(\n\t \t '{$listno}' , now() , '1' ,\n\t \t '{$mscid}' , '{$msclinkman}' , '{$cusid}' ,\n\t \t '{$commid}' , '{$commname}' , '{$level}' , \n\t \t '{$kz}' , '{$gg}' , '{$xsno}' ,\n\t \t '{$xsdate}' , '{$price}' ,'{$quantity}' ,\n\t \t '{$money}' , '{$thquantity}' , '{$ksmoney}' ,\n\t \t '{$czmoney}' , '{$ksyy}' , '{$zlms}' ,\n\t \t '{$memo}' , '{$kstype}' , '{$printsize}' , \n\t \t '{$fqsl}' , '{$printsl}' , '{$shsl}' ,\n\t \t '2' , '{$listid}'\n\t \t )"; $dberp->query($query); } }
case "del": //删除细节表数据 for ($i = 0; $i < count($checkid); $i++) { if (!empty($checkid[$i])) { $query = "delete from tb_paycardstockdetail where fd_skdetail_id = '{$checkid[$i]}'"; $db->query($query); } } countall($listid); echo "<script>alert('删除成功!');location.href='jxcstock.php?listid={$listid}';</script>"; break; case "new": //新增数据 if (empty($listid)) { //如果单据id是不存在的 listnumber_update(1); //保存单据 $query = "select * from tb_paycardstock where fd_stock_no = '{$listno}' "; $db->query($query); if ($db->nf()) { $error = "单据编号已经存在!请查证!"; } else { $query = "insert into tb_paycardstock(\n\t fd_stock_no , fd_stock_suppid , fd_stock_suppno ,\n\t fd_stock_suppname , fd_stock_date , fd_stock_ldr ,\n\t fd_stock_dealwithman , fd_stock_memo \n\t )values(\n\t '{$listno}' , '{$suppid}' , '{$suppno}' ,\n\t '{$suppname}' , '{$date}' , '{$loginstaname}' ,\n\t '{$dealwithman}' , '{$memo_z}' \n\t )"; $db->query($query); //插入单据资料 $listid = $db->insert_id(); //取出刚插入的记录的主关键值的id } } else { //如果单据id号已经存在 $query = "select * from tb_paycardstock where fd_stock_no = '{$listno}' and fd_stock_id <> '{$listid}' ";
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代表负数 }
function order_creat_fplist($listid) { $db = new DB_test(); $db2 = new DB_test(); $dberp = new DB_erp2(); //读取发票申请 $query = "select * from web_invoicesq \n\t left join tb_organmem on fd_organmem_id = fd_ivcsq_memberid\n\t where fd_ivcsq_id = '{$listid}'"; $db->query($query); if ($db->nf()) { $db->next_record(); $iecrid = $db->f(fd_ivcsq_fpcusid); $iecrno = $db->f(fd_ivcsq_fpcusno); $iecrname = $db->f(fd_ivcsq_fpcusname); $orderid = $db->f(fd_ivcsq_orderid); $fptype = $db->f(fd_ivcsq_fptype); $money = $db->f(fd_ivcsq_money); $memo = $db->f(fd_ivcsq_memo); $fpusename = $db->f(fd_organmem_comnpany); $fpuseid = $db->f(fd_ivcsq_memberid); if ($invoicetype == "普通发票") { $invoicetype = 1; } else { $invoicetype = 0; } $s_orderid = implode(",", explode("@@@", $orderid)); $query = "select * from web_order \n where fd_order_id in ({$s_orderid}) "; $db->query($query); if ($db->nf()) { $db->next_record(); $sdcrid = $db->f(fd_order_sdcrid); 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; } } } } } } $issue = date("Y", mktime()) . date("m", mktime()); $listno = listnumber_update(); $query = "insert into tb_invoiceapply(\n\t fd_ieay_listno , fd_ieay_iecrid , fd_ieay_iecrno ,\n\t fd_ieay_iecrname , fd_ieay_sporganid , fd_ieay_date , \n\t fd_ieay_mscompanyid , fd_ieay_issue , fd_ieay_staname ,\n\t fd_ieay_invoicetype , fd_ieay_sdcrid , fd_ieay_cporganid , \n\t fd_ieay_xjmoney , fd_ieay_yhmoney , fd_ieay_spsdcrid ,\n\t fd_ieay_memo , fd_ieay_dziecrid , fd_ieay_sqinvoicetype ,\n\t fd_ieay_sqmscid , fd_ieay_sqyhmoney , fd_ieay_sqxjmoney ,\n\t fd_ieay_websqid , fd_ieay_fpuseid , fd_ieay_fpusename\n\t )values(\n\t '{$listno}' , '{$iecrid}' , '{$iecrno}' ,\n\t '{$iecrname}' , '1' , now() ,\n\t '{$mscompanyid}' , '{$issue}' , '网站' ,\n\t '{$invoicetype}' , '{$sdcrid}' , '1' , \n\t '0' , '{$money}' , '{$sdcrid}' ,\n\t '{$memo}' , '{$iecrid}' , '{$invoicetype}' ,\n\t '{$mscompanyid}' , '0' , '{$money}' ,\n\t '{$listid}' , '{$fpuseid}' , '{$fpusename}'\n\t )"; $dberp->query($query); } }
$arr_num = explode(",", $del_paycardid); $paycardnum = count($arr_num); $query = "update tb_salelistdetail set fd_stdetail_paycardid='{$del_paycardid}', fd_stdetail_quantity='{$paycardnum}' where fd_stdetail_id = '{$delseltid}'"; $db->query($query); $query = "update tb_salelist_tmp set fd_tmpsale_paycardid='{$del_paycardid}' where fd_tmpsale_seltid = '{$delseltid}' and fd_tmpsale_type='sale'"; $db->query($query); $query = "update tb_paycard set fd_paycard_state='1' where fd_paycard_id='{$delpaycard}'"; $db->query($query); countallsalepaycard($listid, 'tb_salelist', 'tb_salelistdetail'); echo "<script>alert('删除成功!');location.href='jxcsale.php?listid={$listid}';</script>"; break; case "new": //新增数据 if (empty($listid)) { //如果单据id是不存在的 listnumber_update(3); //保存单据 $query = "select * from tb_salelist where fd_selt_no = '{$listno}' "; $db->query($query); if ($db->nf()) { $error = "单据编号已经存在!请查证!"; } else { $query = "insert into tb_salelist(\n\t fd_selt_no , fd_selt_date ,fd_selt_cusid , fd_selt_cusno,\n\t\t\t\t\tfd_selt_cusname ,\tfd_selt_skfs ,fd_selt_shaddress ,fd_selt_ldr,fd_selt_dealwithman,\n\t\t\t\t\tfd_selt_saleprice , fd_selt_allquantity,fd_selt_type\n\t )values(\n\t '{$listno}' , '{$date}' ,'{$cusid}' , '{$cusno}',\n\t\t\t\t\t'{$cusname}' , '{$skfs}' ,'{$shaddress}','{$ldr}','{$dealwithma}',\n\t\t\t\t\t'{$saleprice}' \t , '{$allquantity}' , '{$type}'\n\t )"; $db->query($query); //插入单据资料 $listid = $db->insert_id(); //取出刚插入的记录的主关键值的id } } else { //如果单据id号已经存在 $query = "select * from tb_salelist where fd_selt_no = '{$listno}' and fd_selt_id <> '{$listid}' ";
$arr_num = explode(",", $del_paycardid); $paycardnum = count($arr_num); $query = "update tb_salelistbackdetail set fd_stdetail_paycardid='{$del_paycardid}', fd_stdetail_quantity='{$paycardnum}' \n\t\t\twhere fd_stdetail_id = '{$delseltid}'"; $db->query($query); $query = "update tb_salelist_tmp set fd_tmpsale_paycardid='{$del_paycardid}' where fd_tmpsale_seltid = '{$delseltid}' and fd_tmpsale_type='saleback'"; $db->query($query); $query = "update tb_paycard set fd_paycard_state='1' where fd_paycard_id='{$delpaycard}'"; $db->query($query); countallsalepaycard($listid, 'tb_salelistback', 'tb_salelistbackdetail'); echo "<script>alert('删除成功!');location.href='jxcsaleback.php?listid={$listid}';</script>"; break; case "new": //新增数据 if (empty($listid)) { //如果单据id是不存在的 listnumber_update(4); //保存单据 $query = "select * from tb_salelistback where fd_selt_no = '{$listno}' "; $db->query($query); if ($db->nf()) { $error = "单据编号已经存在!请查证!"; } else { $query = "insert into tb_salelistback(\n\t fd_selt_no , fd_selt_date ,fd_selt_cusid , fd_selt_cusno,\n\t\t\t\t\tfd_selt_cusname ,\tfd_selt_skfs ,fd_selt_shaddress,fd_selt_ldr\n\t\t\t\t\t,fd_selt_dealwithman \n\t )values(\n\t '{$listno}' , '{$date}' ,'{$cusid}' , '{$cusno}',\n\t\t\t\t\t'{$cusname}' , '{$skfs}' ,'{$shaddress}','{$ldr}'\n\t\t\t\t\t,'{$dealwithman}'\t\t\n\t )"; $db->query($query); //插入单据资料 $listid = $db->insert_id(); //取出刚插入的记录的主关键值的id } } else { //如果单据id号已经存在 $query = "select * from tb_salelistback where fd_selt_no = '{$listno}' and fd_selt_id <> '{$listid}' ";
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代表负数 } } }
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"); } }