123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- using Common.Model;
- using Common.Wechat;
- using CoreEntity.BAL;
- using CoreEntity.Entity;
- using PublicLibrary.Common;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Text;
- using ZcPeng.PublicLibrary;
- using ZcPeng.weixin.PublicAccount;
- namespace CoreEntity.DAL
- {
- public class PurOrderDAL
- {
- //public const string ENTID = "E2IR7T9P4OI";
- //public const string ORGID = "O2IR7T92J72";
- //public const string DEPID = "K2J67PCXWG4";
- //public const string payorgid = ORGID;
- public const string ruleid = "5x80rrxrb24q2ktt";
- /// 添加采购计划记录到erp
- /// SuppliersId 是根据来往单位(BusinnesDoc)是否供货生成的供应商表(SupplierDoc)记录的id
- /// 如果传入BusinnesId BusinessCode:
- /// 查询 SuppliersId 来往单位(BusinnesDoc)Is_Supp 设置Y
- /// 如果传入SuppliersId:不需要 BusinessId BusinessCode
- public static IDictionary<string, Object> AddOrder(
- string PushAccountId
- ,string PlanBillNo
- , string EntId, int ReceiptMd, int CentPayMd
- , string OrgId, string DeptId
- , string Summaries, string Remark
- , string GoodsId, string SuppliersId
- , string BusinessId, string BusinessCode
- , string StaffDocId
- , string RequestDate
- , string ContactId
- , out int BillNo
- , out int OrderBillCodeNo
- , decimal PrepayAmt
- , string IsPrepay
- , string OppContId
- , List<DataAccessCommand> listcmd = null
- )
- {
- IDictionary<string, Object> resultdic = new Dictionary<string, Object>(6);
- //查询供应商业务员ID
- if(string.IsNullOrEmpty(ContactId))
- ContactId = AccountDAL.getContactor(PushAccountId, BusinessId);
- //查询或生成 SuppliersId
- #region SuppliersId
- string address = "";
- SuppliersId = BusinessId;
- if(SuppliersId == "" || SuppliersId == null)
- {
- ContactDoc cd = ContactDAL.getContactor(ContactId);
- if(cd!=null)
- SuppliersId = cd.ContactId;
- }
- //if (BusinessCode != null && BusinessCode != ""
- // && BusinessId != null && BusinessId != "")
- //{
- // SupplyDoc sups = null;
- // sups = SupplyDAL.getSupply(BusinessCode);
- // if (SuppliersId == null) {
- // SuppliersId = sups.SuppliersId;
- // address = sups.DftAddress;
- // }
- // if (sups != null)
- // {
- // address = sups.DftAddress;
- // }
- //}
- #endregion
- //新建推送记录
- #region 添加订单
- string commandTextRecord = "INSERT INTO "
- + "PurOrderMT (BillNo,"
- + "EntId,"
- + "BillCode,"
- + "RuleId,"
- + "Dates,"
- + "OnTime,"
- + "SysDates,"
- + "IsVAT,"
- + "ExpectDate,"
- + "SuppliersId,"
- + "Address,"
- + "AccptId,"
- + "CurrencyId,"
- + "SaleManId,"
- + "caozy,"
- + "OrgId,"
- + "DeptId,"
- + "ContractCode,"
- + "Delivery,"
- + "PayType,"
- + "OlderNo,"
- + "IsEnd,"
- + "IsDone,"
- + "Summaries,"
- + "Remark,"
- + "PayOrgId,"
- + "ReqDate,"
- + "BillState,"
- + "OppContId,"
- + "IsPrepay,"
- + "PrepayAmt,"
- + "IsDefray,"
- + "IsSuppOut,"
- + "SuppOutDate,"
- + "GoodsGList,"
- //+ "k_isbh,"
- //+ "k_kdcode,"
- //+ "k_qrdates,"
- //+ "k_xspay,"
- //+ "k_pay,"
- //+ "k_isdz,"
- //+ "k_iskd,"
- //+ "ECShopId,"
- //+ "k_issj,"
- + "K_IsBillClose,"
- + "K_CloseStaffId,"
- + "K_CloseTime,"
- + "K_CloseRemark,"
- //+ "K_yingfk,"
- //+ "K_yufk,"
- //+ "K_yfzffs,"
- + "K_AutoTbbl,"
- //+ "ReBillNo,"
- + "K_IsLS,"
- + "K_IsYXD,"
- + "K_yfkye,"
- + "K_yfye,"
- + "K_ye,"
- + "ReBillNo,"
- + "K_ContactId,"
- + "source"
- + ")"
- + " VALUES (@BillNo,@EntId,@BillCode,@RuleId,@Dates,"
- + "@OnTime,@SysDates,"
- + "@IsVAT,@ExpectDate,@SuppliersId,"
- + "@Address,@AccptId,@CurrencyId,@SaleManId,@caozy,"
- + "@OrgId,@DeptId,@ContractCode,@Delivery,@PayType,"
- + "@OlderNo,@IsEnd,@IsDone,@Summaries,@Remark,"
- + "@PayOrgId,@ReqDate,@BillState,@OppContId,@IsPrepay,"
- + "@PrepayAmt,@IsDefray,@IsSuppOut,@SuppOutDate,@GoodsGList,"
- + "@K_IsBillClose,@K_CloseStaffId,@K_CloseTime,@K_CloseRemark,@K_AutoTbbl,"
- + "@K_IsLS,@K_IsYXD,@K_yfkye,@K_yfye,@K_ye,@ReBillNo,@K_ContactId,'coop.360lj.com'"
- + ")";
- string resultRecord;
- //准备参数
- Guid PushRecordId = Guid.NewGuid();
- List<List<Object>> parametersRecord = new List<List<Object>>();
- //订单汇总里面关键的几个字段
- ///一个是billno在智友的syscode表中prefix = 'F'的即为最大编号,
- ///一个是billcode在智友的billcode表中,需要对应的是采购订单的RULEID(固定5x80rrxrb24q2ktt),
- ///从billcode表中取到recnum,billcode的生成规则:PDD+机构标识+8位长度的流水码(recnum,不足补零)例如PDD+Y30+00000058
- ///订单明细中没有BILLCODE,但是有billsn,即明细的序号
- Int32 OrderBillNo = Convert.ToInt32(IDHelper.GetRecNo());
- OrderBillCodeNo = 0;
- BillNo = OrderBillNo;
- if (BillNo == 0)
- {
- return resultdic;
- }
- OrderBillCodeNo = Convert.ToInt32(IDHelper.GetBillCodeRecNo(EntId));
- if (OrderBillCodeNo == 0)
- {
- return resultdic;
- }
- //取ordercode
- string orderNo = OrderBillCodeNo.ToString();
- StringBuilder sb = new StringBuilder("");
- if (orderNo.Length < 8)
- {
- for (int i=0;i< (8 - orderNo.Length); i++)
- {
- sb.Append('0');
- }
- sb.Append(orderNo);
- }
- string orgno = OrgDAL.GetOrgNo(OrgId,EntId);
- String OrderCode = "PDD" + orgno//机构标识
- + sb.ToString();
- parametersRecord.Add(new List<Object>() { "BillNo", OrderBillNo });
- parametersRecord.Add(new List<Object>() { "EntId", EntId });
- parametersRecord.Add(new List<Object>() { "BillCode", OrderCode });
- parametersRecord.Add(new List<Object>() { "RuleId", ruleid });
- parametersRecord.Add(new List<Object>() { "Dates", DateTime.Now.ToString("yyyy-MM-dd") });
- parametersRecord.Add(new List<Object>() { "OnTime", DateTime.Now.ToString("T") });
- parametersRecord.Add(new List<Object>() { "SysDates", DateTime.Now.ToString("yyyy-MM-dd") });
- parametersRecord.Add(new List<Object>() { "IsVAT", 'Y' });
- parametersRecord.Add(new List<Object>() { "ExpectDate", "" });
- parametersRecord.Add(new List<Object>() { "SuppliersId", SuppliersId });
- parametersRecord.Add(new List<Object>() { "Address", address });
- parametersRecord.Add(new List<Object>() { "AccptId", "" });
- parametersRecord.Add(new List<Object>() { "CurrencyId", "CNY" });
- parametersRecord.Add(new List<Object>() { "SaleManId", StaffDocId });
- parametersRecord.Add(new List<Object>() { "caozy", StaffDocId });
- parametersRecord.Add(new List<Object>() { "OrgId", OrgId });
- parametersRecord.Add(new List<Object>() { "DeptId", DeptId });
- parametersRecord.Add(new List<Object>() { "ContractCode", "" });
- parametersRecord.Add(new List<Object>() { "Delivery", ReceiptMd });
- Option PayType;
- PushRecordDAL.OptionCentPayMap.TryGetValue(CentPayMd, out PayType);
- parametersRecord.Add(new List<Object>() { "PayType", PayType.label});
- parametersRecord.Add(new List<Object>() { "OlderNo", "" });
- parametersRecord.Add(new List<Object>() { "IsEnd", 'Y' });
- parametersRecord.Add(new List<Object>() { "IsDone", 'N' });
- parametersRecord.Add(new List<Object>() { "Summaries", "采购订单" });
- parametersRecord.Add(new List<Object>() { "Remark", Remark });
- parametersRecord.Add(new List<Object>() { "PayOrgId", OrgId });
- parametersRecord.Add(new List<Object>() { "ReqDate", RequestDate });
- parametersRecord.Add(new List<Object>() { "BillState", 0});
- parametersRecord.Add(new List<Object>() { "OppContId", OppContId });
- parametersRecord.Add(new List<Object>() { "PrepayAmt", PrepayAmt });
- parametersRecord.Add(new List<Object>() { "IsPrepay", IsPrepay });
- parametersRecord.Add(new List<Object>() { "IsDefray", 'N' });//已支付
- parametersRecord.Add(new List<Object>() { "IsSuppOut", 'N' });//已发货
- parametersRecord.Add(new List<Object>() { "SuppOutDate", "" });//发货日期
- parametersRecord.Add(new List<Object>() { "GoodsGList", "" });//互斥分组列表
- //parametersRecord.Add(new List<Object>() { "k_isbh", "" });
- //parametersRecord.Add(new List<Object>() { "k_kdcode", "" });
- //parametersRecord.Add(new List<Object>() { "k_qrdates", "" });
- //parametersRecord.Add(new List<Object>() { "k_xspay", "" });
- //parametersRecord.Add(new List<Object>() { "k_pay", "" });
- //parametersRecord.Add(new List<Object>() { "k_isdz", "" });
- //parametersRecord.Add(new List<Object>() { "k_iskd", "" });
- //parametersRecord.Add(new List<Object>() { "ECShopId", "" });
- //parametersRecord.Add(new List<Object>() { "k_issj", "" });
- parametersRecord.Add(new List<Object>() { "k_IsBillClose", 'N' });//
- parametersRecord.Add(new List<Object>() { "K_CloseStaffId", "" });
- parametersRecord.Add(new List<Object>() { "K_CloseTime", "" });
- parametersRecord.Add(new List<Object>() { "K_CloseRemark", "" });
- //parametersRecord.Add(new List<Object>() { "K_yingfk", "" });
- //parametersRecord.Add(new List<Object>() { "K_yufk", "" });
- //parametersRecord.Add(new List<Object>() { "K_yfzffs", "" });
- parametersRecord.Add(new List<Object>() { "K_AutoTbbl", 0 });
- //parametersRecord.Add(new List<Object>() { "ReBillNo", "" });
- parametersRecord.Add(new List<Object>() { "K_IsLS", 'Y' });
- parametersRecord.Add(new List<Object>() { "K_IsYXD", 'N' });
- parametersRecord.Add(new List<Object>() { "K_yfkye", null });
- parametersRecord.Add(new List<Object>() { "K_yfye", null });
- parametersRecord.Add(new List<Object>() { "K_ye", null });
- parametersRecord.Add(new List<Object>() { "ReBillNo", PlanBillNo });
- parametersRecord.Add(new List<Object>() { "K_ContactId", ContactId });
- List<SqlParameter> parametersRecord1 = DataAccess.ToParameters(parametersRecord);
- #endregion
- //int successRecord1 = DataAccess.ExecuteCommand(commandTextRecord, parametersRecord1, out resultRecord);
- if (listcmd != null) {
- listcmd.Add(new DataAccessCommand(commandTextRecord, parametersRecord1));
- }
- else {
- int successRecord = DataAccess.ExecuteCommand(commandTextRecord, parametersRecord1, out resultRecord);
- resultdic.Add("successRecord", successRecord);
- resultdic.Add("resultRecord", resultRecord);
- resultdic.Add("OrderBillNo", OrderBillNo);
- resultdic.Add("OrderCode", OrderCode);
- }
- return resultdic;
- }
- public static IDictionary<string, Object> AddOrderDT(
- Int32 OrderBillNo,Int32 BillSn,
- int PlanBillNo, Int32 PlanBillSn,string PlanBillCode,
- string GoodsId,string GoodsSpec, Decimal GoodsGapNum ,
- Decimal LastPrice , Decimal K_Price, string Remark,
- string EntId,string OrgId,
- string BusinessId, string BusinessCode,
- string SuppliersId,
- Decimal PurchaseTotalNum, Int32 SafeDays
- , string LoginAccountId
- , List<DataAccessCommand> listcmd = null)
- {
- IDictionary<string, Object> resultdic = new Dictionary<string, Object>(6);
- //新建推送明细记录
- #region 添加推送明细记录
- string commandTextRecord = "INSERT INTO "
- + "PurOrderDT (BillNo,BillSn,EntId,BillSort,OwnerId,"
- + "GoodsId,PackId,Meas,AngleId,BatchCode,"
- + "ProduceDate,ValDate,BaseNum,Num,Price,"
- + "Taxprice,DedRate,Amount,Rate,Tax,"
- + "TaxAmount,RetailP,IsFree,RfBillNo,RfBillSn,"
- + "ReBillNo,ReBillSn,Remark,WHOrgId,IsDone,"
- + "BasePrice,BaseTaxprice,RfBillCode,ReBillCode,ExecNum,"
- + "CancelNum,RfRuleId,ReRuleId,unit,ContractId,"
- + "APID,SterilCode,K_LastInTaxP,K_Price,K_LastPrice,"
- + "K_IsBillClose,K_CloseStaffId,K_CloseTime,K_CloseRemark,K_Ispfsale,"
- + "K_PFYLSL,K_EntNuM,K_LsNum"
- + ")"
- + " VALUES (@BillNo,@BillSn,@EntId,@BillSort,@OwnerId,@"
- + "GoodsId,@PackId,@Meas,@AngleId,@BatchCode,@"
- + "ProduceDate,@ValDate,@BaseNum,@Num,@Price,@"
- + "Taxprice,@DedRate,@Amount,@Rate,@Tax,@"
- + "TaxAmount,@RetailP,@IsFree,@RfBillNo,@RfBillSn,@"
- + "ReBillNo,@ReBillSn,@Remark,@WHOrgId,@IsDone,@"
- + "BasePrice,@BaseTaxprice,@RfBillCode,@ReBillCode,@ExecNum,@"
- + "CancelNum,@RfRuleId,@ReRuleId,@unit,@ContractId,@"
- + "APID,@SterilCode,@K_LastInTaxP,@K_Price,@K_LastPrice,@"
- + "K_IsBillClose,@K_CloseStaffId,@K_CloseTime,@K_CloseRemark,@K_Ispfsale,@"
- + "K_PFYLSL,@K_EntNuM,@K_LsNum" +
- ")";
- string resultRecord;
- PGPrice pg = IDHelper.GetPackId(GoodsId,EntId);
- string GetPackId = "";
- if (pg!=null)
- GetPackId = pg.PackId;
- //准备参数
- Guid PushRecordId = Guid.NewGuid();
- List<List<Object>> parametersRecord = new List<List<Object>>();
- parametersRecord.Add(new List<Object>() { "BillNo", OrderBillNo });//关联的采购计划BillNo RandHelper.GenerateRandomCode(20)
- parametersRecord.Add(new List<Object>() { "BillSn", BillSn });
- parametersRecord.Add(new List<Object>() { "EntId", EntId });
- parametersRecord.Add(new List<Object>() { "BillSort", BillSn });
-
- parametersRecord.Add(new List<Object>() { "OwnerId", OrgId });
- parametersRecord.Add(new List<Object>() { "GoodsId", GoodsId});
- parametersRecord.Add(new List<Object>() { "PackId", GetPackId });
- parametersRecord.Add(new List<Object>() { "Meas", pg.Meas});
- parametersRecord.Add(new List<Object>() { "AngleId", ""});
- parametersRecord.Add(new List<Object>() { "BatchCode", "" });
- parametersRecord.Add(new List<Object>() { "ProduceDate", "" });
- parametersRecord.Add(new List<Object>() { "ValDate", "" });
- parametersRecord.Add(new List<Object>() { "BaseNum", GoodsGapNum });
- parametersRecord.Add(new List<Object>() { "Num", GoodsGapNum });
- parametersRecord.Add(new List<Object>() { "Price", LastPrice });
- parametersRecord.Add(new List<Object>() { "Taxprice", LastPrice });
- parametersRecord.Add(new List<Object>() { "DedRate", 100});
- decimal amount = LastPrice* GoodsGapNum;
- parametersRecord.Add(new List<Object>() { "Amount", amount });
- parametersRecord.Add(new List<Object>() { "Rate", 0});
- parametersRecord.Add(new List<Object>() { "Tax", 0});
- parametersRecord.Add(new List<Object>() { "TaxAmount", amount });
- parametersRecord.Add(new List<Object>() { "RetailP", 0});
- parametersRecord.Add(new List<Object>() { "IsFree", 'N' });
- parametersRecord.Add(new List<Object>() { "RfBillNo", 0});
- parametersRecord.Add(new List<Object>() { "RfBillSn", 0});
- parametersRecord.Add(new List<Object>() { "ReBillNo", PlanBillNo });
- parametersRecord.Add(new List<Object>() { "ReBillSn", PlanBillSn });
- parametersRecord.Add(new List<Object>() { "Remark", Remark});
- parametersRecord.Add(new List<Object>() { "WHOrgId", OrgId});
- parametersRecord.Add(new List<Object>() { "IsDone", 'N'});
- parametersRecord.Add(new List<Object>() { "BasePrice", LastPrice});
- parametersRecord.Add(new List<Object>() { "BaseTaxprice", LastPrice });
- parametersRecord.Add(new List<Object>() { "RfBillCode", ""});
- parametersRecord.Add(new List<Object>() { "ReBillCode", PlanBillCode });
- parametersRecord.Add(new List<Object>() { "ExecNum", 0});
- parametersRecord.Add(new List<Object>() { "CancelNum", 0});
- parametersRecord.Add(new List<Object>() { "RfRuleId", "" });
- parametersRecord.Add(new List<Object>() { "ReRuleId", "" });
- parametersRecord.Add(new List<Object>() { "unit", pg.unit});
- parametersRecord.Add(new List<Object>() { "ContractId", "" });
- parametersRecord.Add(new List<Object>() { "APID", "" });
- parametersRecord.Add(new List<Object>() { "SterilCode", "" });
- parametersRecord.Add(new List<Object>() { "K_LastInTaxP", 0});
- parametersRecord.Add(new List<Object>() { "K_Price", K_Price});
- parametersRecord.Add(new List<Object>() { "K_LastPrice",0 });
- parametersRecord.Add(new List<Object>() { "K_IsBillClose", 'N'});
- parametersRecord.Add(new List<Object>() { "K_CloseStaffId", ""});
- parametersRecord.Add(new List<Object>() { "K_CloseTime", "" });
- parametersRecord.Add(new List<Object>() { "K_CloseRemark", "" });
- parametersRecord.Add(new List<Object>() { "K_Ispfsale", 'N'});
- parametersRecord.Add(new List<Object>() { "K_PFYLSL", null});
- parametersRecord.Add(new List<Object>() { "K_EntNuM", null });
- parametersRecord.Add(new List<Object>() { "K_LsNum", null });
- List<SqlParameter> parametersRecord1 = DataAccess.ToParameters(parametersRecord);
- #endregion
- if(listcmd ==null)
- {
- int successRecord = DataAccess.ExecuteCommand(commandTextRecord, parametersRecord1, out resultRecord);
- resultdic.Add("successRecord", successRecord);
- resultdic.Add("resultRecord", resultRecord);
- }
- else
- {
- listcmd.Add(new DataAccessCommand(commandTextRecord, parametersRecord1));
- }
- return resultdic;
- }
- //IsComplete 1
- public static int UpdateOrderState(string FeedbackId, string RecordId,int PushAccountId,List<DataAccessCommand> listcmd)
- {
- #region 更新明细
- string commandTextRecord = "UPDATE " + Config.TablePrefix + "PushFeedback " +
- " SET HasOrder = @HasOrder ," +
- " State = 4, " +
- " ConfirmOrderTime = @ConfirmOrderTime," +
- " ConfirmOrderPerson = @ConfirmOrderPerson" +
- " WHERE Id= @FeedbackId " +
- " AND State = 3 " +
- " AND PushAccountId=" + PushAccountId;
- string resultRecord;
- //准备参数
- List<List<Object>> parametersRecord = new List<List<Object>>();
- parametersRecord.Add(new List<Object>() { "FeedbackId", Guid.Parse(FeedbackId) });
- parametersRecord.Add(new List<Object>() { "HasOrder", 1 });
- parametersRecord.Add(new List<Object>() { "ConfirmOrderTime", DateTime.Now });
- parametersRecord.Add(new List<Object>() { "ConfirmOrderPerson", PushAccountId });
- List<SqlParameter> parametersRecord1 = DataAccess.ToParameters(parametersRecord);
- #endregion
- if (listcmd == null)
- {
- int successRecord = DataAccess.ExecuteCommand(commandTextRecord, parametersRecord1, out resultRecord);
- if (successRecord > 0)
- return 1;
- else
- return 0;
- }
- else
- {
- listcmd.Add(new DataAccessCommand(commandTextRecord, parametersRecord1));
- return 1;
- }
- }
- public static int UpdateRecordOrderState(string RecordId,string LoginAccountId)
- {
- #region 更新记录
- string commandTextFeed = "UPDATE " + Config.TablePrefix + "PushRecord " +
- " SET HasOrder = @HasOrder " +
- //" ,OrderTime = @OrderTime," +
- " WHERE Id= @RecordId "
- // +" AND (IsComplete = 1 ) "
- ;
- string resultFeed;
- //准备参数
- List<List<Object>> parametersFeed = new List<List<Object>>();
- parametersFeed.Add(new List<Object>() { "RecordId", Guid.Parse(RecordId) });
- parametersFeed.Add(new List<Object>() { "HasOrder", 1 });
- //parametersFeed.Add(new List<Object>() { "OrderTime", DateTime.Now });
- List<SqlParameter> parametersFeed1 = DataAccess.ToParameters(parametersFeed);
- int successFeed = DataAccess.ExecuteCommand(commandTextFeed, parametersFeed1, out resultFeed);
- #endregion
- return successFeed;
- }
- }
- }
|