123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684 |
- $PBExportHeader$uo_saletask_altermtrl.sru
- forward
- global type uo_saletask_altermtrl from nonvisualobject
- end type
- end forward
- global type uo_saletask_altermtrl from nonvisualobject
- end type
- global uo_saletask_altermtrl uo_saletask_altermtrl
- type variables
- long uo_billid
- string uo_billcode
- int uo_option_m_msttake
- int uo_option_price_rmb
- end variables
- forward prototypes
- public function integer p_getflag (long arg_billid, ref integer arg_flag, ref string arg_msg)
- public function integer updatebegin (long arg_billid, ref string arg_msg)
- public function integer save (s_saletask_altermtrl arg_s_altermtrl, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
- public function integer del (long arg_billid, ref string arg_msg, boolean arg_ifcommit)
- public function integer getinfo (long arg_billid, ref s_saletask_altermtrl_mx arg_ref_mx[], ref long arg_arr_cnt, ref string arg_msg)
- public function integer audit (long arg_billid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit)
- public function integer add_dscrp (long arg_billid, string arg_newdescppart, ref string arg_msg, boolean arg_ifcommit)
- end prototypes
- public function integer p_getflag (long arg_billid, ref integer arg_flag, ref string arg_msg);Int rslt = 1
- SELECT flag
- INTO :arg_flag
- FROM u_saletask_altermtrl
- WHERE billid = :arg_billid;
- IF sqlca.SQLCode <> 0 THEN
- ARG_MSG = '查询单据审核标记失败,'+sqlca.SQLErrText
- rslt = 0
- GOTO ext
- END IF
- ext:
- RETURN rslt
- end function
- public function integer updatebegin (long arg_billid, ref string arg_msg);Int rslt = 1
- Int li_flag
- Long cnt
- If arg_billid <= 0 Then
- rslt = 0
- arg_msg = '错误单据唯一码'
- Goto ext
- End If
- If p_getflag(arg_billid,li_flag,arg_msg) = 0 Then
- rslt = 0
- Goto ext
- End If
- If li_flag = 1 Then
- rslt = 0
- arg_msg = '单据已经审核,不可以再修改'
- Goto ext
- End If
- ext:
- Return rslt
- end function
- public function integer save (s_saletask_altermtrl arg_s_altermtrl, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Integer rslt = 1,cnt = 0
- DateTime server_dt
- Long ll_billid,it_mxbt,i
- String ls_sccode,ls_billcode
- If IsNull(arg_s_altermtrl.scid) Then arg_s_altermtrl.scid = 0
- If IsNull(arg_s_altermtrl.billid) Then arg_s_altermtrl.billid = 0
- If IsNull(arg_s_altermtrl.relcode) Then arg_s_altermtrl.relcode = ''
- If IsNull(arg_s_altermtrl.rep) Then arg_s_altermtrl.rep = ''
- If IsNull(arg_s_altermtrl.dscrp) Then arg_s_altermtrl.dscrp = ''
- If arg_s_altermtrl.rep = '' Then
- arg_msg = '请输入经手人'
- rslt = 0
- Goto ext
- End If
- If arg_s_altermtrl.scid < 0 Then
- arg_msg = '请选择分部'
- rslt = 0
- Goto ext
- End If
- Select Top 1 getdate() Into :server_dt From u_user;
- If sqlca.SQLCode <> 0 Then
- rslt = 0
- arg_msg = "查询操作失败,日期 "
- Goto ext
- End If
- it_mxbt = UpperBound(arg_s_altermtrl.arg_s_mx)
- If it_mxbt <= 0 Then
- rslt = 0
- arg_msg = "没有正确明细内容"
- Goto ext
- End If
- //新增类型,检查 工组 对应 车间
- For i = 1 To it_mxbt
- If arg_s_altermtrl.arg_s_mx[i].taskid = 0 Then
- rslt = 0
- arg_msg = "行"+String(i)+ ",请选择订单明细"
- Goto ext
- End If
-
- If arg_s_altermtrl.arg_s_mx[i].mtrlid_ori = arg_s_altermtrl.arg_s_mx[i].mtrlid_new And &
- arg_s_altermtrl.arg_s_mx[i].status_ori = arg_s_altermtrl.arg_s_mx[i].status_new And &
- arg_s_altermtrl.arg_s_mx[i].woodcode_ori = arg_s_altermtrl.arg_s_mx[i].woodcode_new And &
- arg_s_altermtrl.arg_s_mx[i].pcode_ori = arg_s_altermtrl.arg_s_mx[i].pcode_new And &
- arg_s_altermtrl.arg_s_mx[i].enprice_ori = arg_s_altermtrl.arg_s_mx[i].enprice_new Then
- rslt = 0
- arg_msg = '行'+String(i)+',没有任何修改,请检查'
- Goto ext
-
- End If
- Next
- If arg_s_altermtrl.billid = 0 Then
- ll_billid = f_sys_scidentity(0,"u_saletask_altermtrl","billid",arg_msg,True,id_sqlca)
-
- If ll_billid <= 0 Then
- rslt = 0
- Goto ext
- End If
-
- If f_get_sccode(0,sqlca,ls_sccode,arg_msg) = 0 Then
- rslt = 0
- Goto ext
- End If
-
- ls_billcode = getid(0,ls_sccode + 'TA',Date(server_dt),False,sqlca)
-
- If ls_billcode = "err" Then
- rslt = 0
- arg_msg = "无法获取单据编号"+"~n"+sqlca.SQLErrText
- Goto ext
- End If
-
- Insert Into u_saletask_altermtrl
- (scid,
- billid,
- billcode,
- billdate,
- relcode,
- rep,
- dscrp,
- opdate,
- opemp)
- Values
- (:arg_s_altermtrl.scid,
- :ll_billid,
- :ls_billcode,
- :arg_s_altermtrl.billdate,
- :arg_s_altermtrl.relcode,
- :arg_s_altermtrl.rep,
- :arg_s_altermtrl.dscrp,
- getdate(),
- :arg_opemp);
- If sqlca.SQLCode <> 0 Then
- rslt = 0
- arg_msg = "因网络或其它原因导致建立单据操作失败"+"~n"+sqlca.SQLErrText
- Goto ext
- End If
-
-
-
- uo_billid = ll_billid
- uo_billcode = ls_billcode
-
- Else
- Update u_saletask_altermtrl
- Set billdate = :arg_s_altermtrl.billdate,
- rep = :arg_s_altermtrl.rep,
- dscrp = :arg_s_altermtrl.dscrp,
- relcode = :arg_s_altermtrl.relcode,
- moddate = getdate(),
- modemp = :arg_opemp
- Where billid = :arg_s_altermtrl.billid
- And flag = 0 ;
- If sqlca.SQLCode <> 0 Or sqlca.SQLNRows <= 0 Then
- rslt = 0
- arg_msg = "因网络或其它原因导致更新单据操作失败"+"~n"+sqlca.SQLErrText
- Goto ext
- End If
-
- Delete From u_saletask_altermtrl_mx
- Where billid = :arg_s_altermtrl.billid;
- If sqlca.SQLCode <> 0 Then
- rslt = 0
- arg_msg = "删除旧有明细操作失败"+"~n"+sqlca.SQLErrText
- Goto ext
- End If
-
- uo_billid = arg_s_altermtrl.billid
-
- End If
- For i = 1 To it_mxbt
- Insert Into u_saletask_altermtrl_mx
- (scid,
- billid,
- printid,
- taskid,
- taskprintid,
- taskcode,
- cusid,
- mtrlid_ori,
- mtrlid_new,
- status_ori,
- status_new,
- woodcode_ori,
- woodcode_new,
- pcode_ori,
- pcode_new,
- enprice_ori,
- enprice_new,
- mxdscrp)
- Values
- (:arg_s_altermtrl.scid,
- :uo_billid,
- :arg_s_altermtrl.arg_s_mx[i].printid,
- :arg_s_altermtrl.arg_s_mx[i].taskid,
- :arg_s_altermtrl.arg_s_mx[i].taskprintid,
- :arg_s_altermtrl.arg_s_mx[i].taskcode,
- :arg_s_altermtrl.arg_s_mx[i].cusid,
- :arg_s_altermtrl.arg_s_mx[i].mtrlid_ori,
- :arg_s_altermtrl.arg_s_mx[i].mtrlid_new,
- :arg_s_altermtrl.arg_s_mx[i].status_ori,
- :arg_s_altermtrl.arg_s_mx[i].status_new,
- :arg_s_altermtrl.arg_s_mx[i].woodcode_ori,
- :arg_s_altermtrl.arg_s_mx[i].woodcode_new,
- :arg_s_altermtrl.arg_s_mx[i].pcode_ori,
- :arg_s_altermtrl.arg_s_mx[i].pcode_new,
- :arg_s_altermtrl.arg_s_mx[i].enprice_ori,
- :arg_s_altermtrl.arg_s_mx[i].enprice_new,
- :arg_s_altermtrl.arg_s_mx[i].mxdscrp);
- If sqlca.SQLCode <> 0 Then
- uo_billid = arg_s_altermtrl.billid
- rslt = 0
- arg_msg = "因网络或其它原因导致插入明细操作失败"+"~n"+sqlca.SQLErrText
- Goto ext
- End If
- Next
- ext:
- If rslt = 0 Then
- Rollback;
- ElseIf arg_ifcommit And rslt = 1 Then
- Commit;
- End If
- Return rslt
- end function
- public function integer del (long arg_billid, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
- Int li_flag,li_priceflag
- IF arg_billid <= 0 THEN
- rslt = 0
- arg_msg = '错误单据唯一码'
- GOTO ext
- END IF
- IF p_getflag(arg_billid,li_flag,arg_msg) = 0 THEN
- rslt = 0
- GOTO ext
- END IF
- IF li_flag = 1 THEN
- rslt = 0
- arg_msg = '单据不是在待审状态,不可以删除'
- GOTO ext
- END IF
- DELETE FROM u_saletask_altermtrl
- WHERE billid = :arg_billid;
- IF sqlca.SQLCode <> 0 THEN
- rslt = 0
- arg_msg = "删除单据操作失败"+"~n"+sqlca.SQLErrText
- GOTO ext
- END IF
- DELETE FROM u_saletask_altermtrl_mx
- WHERE billid = :arg_billid;
- IF sqlca.SQLCode <> 0 THEN
- rslt = 0
- arg_msg = "删除单据明细操作失败"+"~n"+sqlca.SQLErrText
- GOTO ext
- END IF
- ext:
- IF rslt = 0 THEN
- ROLLBACK;
- ELSEIF rslt = 1 AND arg_ifcommit THEN
- COMMIT;
- END IF
- RETURN rslt
- end function
- public function integer getinfo (long arg_billid, ref s_saletask_altermtrl_mx arg_ref_mx[], ref long arg_arr_cnt, ref string arg_msg);Int rslt = 1
- Long i = 1,no_mxcheck = 0
- If arg_billid <= 0 Then
- rslt = 0
- arg_msg = '错误单据唯一码'
- Goto ext
- End If
- //用游标读取明细
- Declare cur_mx Cursor For
- Select scid,
- printid,
- taskid,
- taskprintid,
- taskcode,
- cusid,
- mtrlid_ori,
- mtrlid_new,
- status_ori,
- status_new,
- woodcode_ori,
- woodcode_new,
- pcode_ori,
- pcode_new,
- enprice_ori,
- enprice_new,
- mxdscrp
- From u_saletask_altermtrl_mx
- Where u_saletask_altermtrl_mx.billid = :arg_billid
- Order By u_saletask_altermtrl_mx.printid;
-
- Open cur_mx;
- Fetch cur_mx Into
- :arg_ref_mx[i].scid,
- :arg_ref_mx[i].printid,
- :arg_ref_mx[i].taskid,
- :arg_ref_mx[i].taskprintid,
- :arg_ref_mx[i].taskcode,
- :arg_ref_mx[i].cusid,
- :arg_ref_mx[i].mtrlid_ori,
- :arg_ref_mx[i].mtrlid_new,
- :arg_ref_mx[i].status_ori,
- :arg_ref_mx[i].status_new,
- :arg_ref_mx[i].woodcode_ori,
- :arg_ref_mx[i].woodcode_new,
- :arg_ref_mx[i].pcode_ori,
- :arg_ref_mx[i].pcode_new,
- :arg_ref_mx[i].enprice_ori,
- :arg_ref_mx[i].enprice_new,
- :arg_ref_mx[i].mxdscrp;
-
- Do While sqlca.SQLCode = 0
- i++
- Fetch cur_mx Into
- :arg_ref_mx[i].scid,
- :arg_ref_mx[i].printid,
- :arg_ref_mx[i].taskid,
- :arg_ref_mx[i].taskprintid,
- :arg_ref_mx[i].taskcode,
- :arg_ref_mx[i].cusid,
- :arg_ref_mx[i].mtrlid_ori,
- :arg_ref_mx[i].mtrlid_new,
- :arg_ref_mx[i].status_ori,
- :arg_ref_mx[i].status_new,
- :arg_ref_mx[i].woodcode_ori,
- :arg_ref_mx[i].woodcode_new,
- :arg_ref_mx[i].pcode_ori,
- :arg_ref_mx[i].pcode_new,
- :arg_ref_mx[i].enprice_ori,
- :arg_ref_mx[i].enprice_new,
- :arg_ref_mx[i].mxdscrp;
- Loop
- Close cur_mx;
- //检验明细是否读入完整
- Select count(*) Into :no_mxcheck
- From u_saletask_altermtrl_mx
- Where billid = :arg_billid;
- If sqlca.SQLCode <> 0 Then
- rslt = 0
- arg_msg = "查询操作失败,单据明细数量"
- Goto ext
- End If
- If i <> (no_mxcheck + 1) Then
- rslt = 0
- arg_msg = "查询操作失败,单据明细"
- Goto ext
- End If
- arg_arr_cnt = i - 1
- ext:
- Return rslt
- end function
- public function integer audit (long arg_billid, string arg_opemp, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
- Int li_flag
- Long ll_arr_cnt
- Long ll_i
- If uo_option_m_msttake = -1000 Then
- arg_msg = '选项:[045]系统使用多币种应收帐,读取初始默认值失败,操作取消!'
- rslt = 0
- Goto ext
- End If
- If uo_option_price_rmb = -1000 Then
- arg_msg = '选项:[238]销售单价按人民币单价折算,读取初始默认值失败,操作取消!'
- rslt = 0
- Goto ext
- End If
- s_saletask_altermtrl_mx s_ref_mx[]
- If arg_billid <= 0 Then
- rslt = 0
- arg_msg = '错误单据唯一码'
- Goto ext
- End If
- If p_getflag(arg_billid,li_flag,arg_msg) = 0 Then
- rslt = 0
- Goto ext
- End If
- If li_flag <> 0 Then
- rslt = 0
- arg_msg = '单据不是在待审核状态,不可以审核'
- Goto ext
- End If
- If getinfo(arg_billid,s_ref_mx,ll_arr_cnt,arg_msg) = 0 Then
- rslt = 0
- Goto ext
- End If
- Decimal mrate,msttakeamt,saleqty,rebate
- Decimal msttakeamt_new,fprice_new,enacprice_new,price_new
- decimal consignedQty
- Long cnt
- For ll_i = 1 To ll_arr_cnt
- //查询是否已排产
- cnt = 0
-
- Select count(*)
- Into :cnt
- From u_order_ml_mx
- Where scid = :s_ref_mx[ll_i].scid
- And taskid = :s_ref_mx[ll_i].taskid
- And taskmxid = :s_ref_mx[ll_i].taskprintid;
- If sqlca.SQLCode <> 0 Then
- rslt = 0
- arg_msg = '第'+String(ll_i)+'行,查询订单明细是否已排产失败 '+sqlca.SQLErrText
- Goto ext
- End If
-
- If cnt > 0 Then
- rslt = 0
- arg_msg = '第'+String(ll_i)+'行,订单明细已排产,不能变更'
- Goto ext
- End If
-
- //查询是否有库存分配
- cnt = 0
- Select count(*)
- Into :cnt
- From u_mtrlware_assign
- Where u_mtrlware_assign.Scid = :s_ref_mx[ll_i].scid And
- u_mtrlware_assign.Relbillid = :s_ref_mx[ll_i].taskid And
- u_mtrlware_assign.Relprintid = :s_ref_mx[ll_i].taskprintid And
- u_mtrlware_assign.assigntype = 1;
- If sqlca.SQLCode <> 0 Then
- rslt = 0
- arg_msg = '第'+String(ll_i)+'行,查询订单明细是否已有库存分配失败 '+sqlca.SQLErrText
- Goto ext
- End If
-
- If cnt > 0 Then
- rslt = 0
- arg_msg = '第'+String(ll_i)+'行,订单明细有库存分配,不能变更'
- Goto ext
- End If
-
- Select u_SaleTask.mrate,
- u_SaleTask.msttakeamt,
- u_SaleTaskMx.SaleQty,
- u_SaleTaskMx.rebate,
- u_SaleTaskMx.consignedQty
- Into :mrate,
- :msttakeamt,
- :saleqty,
- :rebate,
- :consignedQty
- From u_SaleTaskMx Inner JOIN
- u_SaleTask ON u_SaleTaskMx.scid = u_SaleTask.scid And
- u_SaleTaskMx.TaskID = u_SaleTask.TaskID
- Where u_SaleTaskMx.scid = :s_ref_mx[ll_i].scid
- And u_SaleTaskMx.taskid = :s_ref_mx[ll_i].taskid
- And u_SaleTaskMx.printid = :s_ref_mx[ll_i].taskprintid;
- If sqlca.SQLCode <> 0 Then
- rslt = 0
- arg_msg = '第'+String(ll_i)+'行,查询订单明细信息失败 '+sqlca.SQLErrText
- Goto ext
- End If
-
- if consignedQty > 0 then
- rslt = 0
- arg_msg = '第'+String(ll_i)+'行,订单明细有已发货数,不能变更'
- Goto ext
- End If
-
- If uo_option_price_rmb = 0 Then
- fprice_new = s_ref_mx[ll_i].enprice_new * mrate
-
- If mrate = 0 Then
- enacprice_new = fprice_new * rebate
- Else
- enacprice_new = fprice_new * rebate / mrate
- End If
-
- price_new = fprice_new * rebate
-
- Else
- fprice_new = Round(s_ref_mx[ll_i].enprice_new * mrate,2)
-
- If mrate = 0 Then
- enacprice_new = Round(fprice_new * rebate,2)
- Else
- enacprice_new = Round(fprice_new * rebate / mrate,2)
- End If
-
- price_new = Round(fprice_new * rebate,2)
-
- End If
-
- Update u_saletaskmx
- Set mtrlid = :s_ref_mx[ll_i].mtrlid_new,
- status = :s_ref_mx[ll_i].status_new,
- woodcode = :s_ref_mx[ll_i].woodcode_new,
- pcode = :s_ref_mx[ll_i].pcode_new,
- enprice = :s_ref_mx[ll_i].enprice_new,
- fprice = :fprice_new,
- price = :price_new,
- enacprice = :enacprice_new
- Where scid = :s_ref_mx[ll_i].scid
- And taskid = :s_ref_mx[ll_i].taskid
- And printid = :s_ref_mx[ll_i].taskprintid;
- If sqlca.SQLCode <> 0 Then
- rslt = 0
- arg_msg = '第'+String(ll_i)+'行,更新订单明细信息失败 '+sqlca.SQLErrText
- Goto ext
- End If
-
- If uo_option_m_msttake = 1 Then //使用多币种
- msttakeamt_new = msttakeamt + Round((s_ref_mx[ll_i].enprice_new - s_ref_mx[ll_i].enprice_ori) * saleqty * rebate,2)
- Else // 系统不使用多币种,转换为人民币
- msttakeamt_new = msttakeamt + Round((s_ref_mx[ll_i].enprice_new - s_ref_mx[ll_i].enprice_ori) * mrate * saleqty * rebate,2)
- End If
-
- Update u_saletask
- Set msttakeamt = :msttakeamt_new
- Where scid = :s_ref_mx[ll_i].scid
- And taskid = :s_ref_mx[ll_i].taskid;
- If sqlca.SQLCode <> 0 Then
- rslt = 0
- arg_msg = '第'+String(ll_i)+'行,更新订单应收金额失败 '+sqlca.SQLErrText
- Goto ext
- End If
-
- Next
- //更新审核标记
- Update u_saletask_altermtrl
- Set auditemp = :arg_opemp,
- auditdate = getdate(),
- flag = 1
- Where billid = :arg_billid
- And flag = 0;
- If sqlca.SQLCode <> 0 Then
- rslt = 0
- arg_msg = "因网络或其它原因导致单据审核操作失败"+"~n"+sqlca.SQLErrText
- Goto ext
- ElseIf sqlca.SQLNRows = 0 Then
- rslt = 0
- arg_msg = "单据正在审核,请稍后查询。"+"~n"+sqlca.SQLErrText
- Goto ext
- End If
- ext:
- If rslt = 0 Then
- Rollback;
- ElseIf rslt = 1 And arg_ifcommit Then
- Commit;
- End If
- Return rslt
- end function
- public function integer add_dscrp (long arg_billid, string arg_newdescppart, ref string arg_msg, boolean arg_ifcommit);Int rslt = 1
- Int li_flag
- IF arg_newdescppart = '' THEN
- rslt = 0
- arG_MSG = "要添加内容为空,操作取消"
- GOTO ext
- END IF
- IF p_getflag(arg_billid,li_flag,arG_MSG) = 0 THEN
- rslt = 0
- GOTO ext
- END IF
- IF li_flag = 0 THEN
- rslt = 0
- arG_MSG = "待审核状态下不可用"
- GOTO ext
- END IF
- UPDATE u_saletask_altermtrl
- SET DSCRP = DSCRP+' '+:arg_newdescppart
- WHERE u_saletask_altermtrl.billid = :arg_billid;
- IF SQLCA.SQLCode <> 0 THEN
- rslt = 0
- arG_MSG = "因网络或其它原因导致添加备注操作失败"+"~n"+SQLCA.SQLErrText
- GOTO ext
- END IF
- ext:
- IF rslt = 0 THEN
- ROLLBACK;
- ELSEIF rslt = 1 AND arg_ifcommit THEN
- COMMIT;
- END IF
- Return (rslt)
- end function
- on uo_saletask_altermtrl.create
- call super::create
- TriggerEvent( this, "constructor" )
- end on
- on uo_saletask_altermtrl.destroy
- TriggerEvent( this, "destructor" )
- call super::destroy
- end on
|