using Model;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using Pub_Class;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Data.SqlClient;
|
using System.Web.Http;
|
using WebAPI.Models;
|
using SyntacticSugar.constant;
|
|
namespace WebAPI.Controllers
|
{
|
//销售核销
|
public class Cg_POStockInBillList_SecController : ApiController
|
{
|
//获取系统参数
|
Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
|
public DBUtility.ClsPub.Enum_BillStatus BillStatus;
|
|
|
private json objJsonResult = new json();
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
DataSet ds;
|
#region 加入单据到待核销队列
|
[Route("Cg_POStockInBillList_Sec/addBillToWaitSecList")]
|
[HttpGet]
|
public object addBillToWaitSecList(int hmainid, string user)
|
{
|
try
|
{
|
string sql = "select * from Kf_ICStockBillMain where HBillType = '1201' and HInterID = " + hmainid;
|
ds = oCN.RunProcReturn(sql, "Kf_ICStockBillMain");
|
|
string sql1 = "insert into Cg_POStockInBillList_Sec(HMaker,HMakeDate,HMainSourceInterID,MainSourceBillNo,HMainSourceBillType) " +
|
" values(" +
|
"'" + user + "'" +
|
"," + "getdate()" + "" +
|
"," + hmainid + "" +
|
",'" + ds.Tables[0].Rows[0]["HBillNo"].ToString() + "'" +
|
",'" + "1201" + "'" +
|
")";
|
oCN.RunProc(sql1);
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 核销生成应收单
|
[Route("Cg_POStockInBillList_Sec/SecToPayableBill")]
|
[HttpGet]
|
public object SecToPayableBill(string hmainidList, string user)
|
{
|
oCN.BeginTran();
|
try
|
{
|
//将待核销列表中的数据标记为已核销
|
string sql0 = $"update Cg_POStockInBillList_Sec set HSecEmp = '{user}',HSecTime = getdate() where HMainSourceInterID in ({hmainidList})";
|
oCN.RunProc(sql0);
|
|
//生成应付单
|
string sql = $"select * from h_v_Kf_POStockInBillEdit where hmainid in ({ hmainidList})";
|
ds = oCN.RunProcReturn(sql, "h_v_Kf_POStockInBillEdit");
|
DAL.ClsCg_PayableBill oBill = new DAL.ClsCg_PayableBill();
|
oBill.omodel.HInterID = DBUtility.ClsPub.CreateBillID("1114", ref DBUtility.ClsPub.sExeReturnInfo);
|
oBill.omodel.HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("1114", ref DBUtility.ClsPub.sExeReturnInfo,false);
|
oBill.omodel.HDate = DateTime.Now;
|
oBill.omodel.HPeriod = DateTime.Now.Month;
|
oBill.omodel.HYear = DateTime.Now.Year;
|
oBill.omodel.HMainSourceInterID = 0;
|
oBill.omodel.HMainSourceEntryID = 0;
|
oBill.omodel.HMainSourceBillNo = "";
|
oBill.omodel.HMainSourceBillType = "1201";
|
oBill.omodel.HMaker = user;
|
oBill.omodel.HMakeDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
oBill.omodel.HSSID = 0; ;
|
oBill.omodel.HPSStyleID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HPSStyleID"]); ; ;
|
oBill.omodel.HReceiveDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
oBill.omodel.HSupID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HSupID"]);
|
oBill.omodel.HCurID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HCurID"]);
|
oBill.omodel.HExRate = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[0]["汇率"]);
|
oBill.omodel.HEmpID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HEmpID"]);
|
oBill.omodel.HMangerID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HManagerID"]);
|
oBill.omodel.HDeptID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HDeptID"]);
|
oBill.omodel.HExplanation = "";
|
oBill.omodel.HInnerBillNo = "";
|
oBill.omodel.HRemark = "";
|
oBill.omodel.HInvoiceBillNo = "";
|
oBill.omodel.HProjectID = 0;
|
|
for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
{
|
Model.ClsCg_PayableSub oItemSub = new Model.ClsCg_PayableSub();
|
oItemSub.HInterID = oBill.omodel.HInterID;
|
oItemSub.HEntryID = (i + 1);
|
oItemSub.HBillNo_bak = oBill.omodel.HBillNo;
|
oItemSub.HMaterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HMaterID"]);
|
oItemSub.HUnitID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HUnitID"]);
|
oItemSub.HQty = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["实收数量"]);
|
oItemSub.HPrice = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["单价"]);
|
oItemSub.HTaxPrice = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["含税单价"]);
|
oItemSub.HDiscountRate = 1; ;
|
oItemSub.HRelTaxPrice = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["含税单价"]);
|
oItemSub.HTaxRate = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["税率"]);
|
oItemSub.HTaxMoney = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["金额"]) * DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["税率"]);
|
oItemSub.HlineTotal = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["含税金额"]);
|
oItemSub.HlineTotalBB = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["含税金额"]) * oBill.omodel.HExRate;
|
oItemSub.HMoney = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["金额"]);
|
oItemSub.HMoneyBB = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["金额"]) * oBill.omodel.HExRate;
|
oItemSub.HRemark = "";
|
oItemSub.HSourceInterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["hmainid"]);
|
oItemSub.HSourceEntryID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["hsubid"]);
|
oItemSub.HSourceBillNo = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["单据号"]);
|
oItemSub.HSourceBillType = "1201";
|
oItemSub.HRelationQty = 0;
|
oItemSub.HRelationMoney = 0;
|
|
oBill.DetailColl.Add(oItemSub);
|
}
|
|
bool bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
|
|
if (bResult)
|
{
|
oCN.Commit();
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "核销成功!";
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
else
|
{
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "核销失败!" + DBUtility.ClsPub.sExeReturnInfo;
|
objJsonResult.data = 1;
|
return objJsonResult;
|
}
|
}
|
catch (Exception e)
|
{
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
}
|
}
|