| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637 |
- package saorder;
- import baseclass.tools.GetFieldsName;
- import baseclass.tools.Math;
- import ficashbill.ficashbill;
- import icstockbill.icstockbill;
- import openapi.base.SQLFactory;
- import openapi.base.data.Row;
- import openapi.base.data.Rows;
- import openapi.base.data.db.DBConnect;
- import p2.pao.PaoRemote;
- import p2.pao.PaoSet;
- import p2.pao.PaoSetRemote;
- import p2.util.P2AppException;
- import p2.util.P2Exception;
- import sainvoice.sainvoice;
- import saorder.base.BaseSaorder;
- import saorderdetail.saorderdetail;
- import taccbal.taccbal;
- import titem.titem;
- import twriteoffbill.twriteoffbill_orderchange;
- import java.util.*;
- public class saorder extends BaseSaorder {
- public saorder(PaoSet arg0) {
- super(arg0);
- }
- @Override
- public void init() throws P2Exception {
- super.init();
- try {
- if (!toBeAdded() && getThisPaoSet().getApp() != null) {
- if (!"新建".equals(getString("fstatus"))) {
- setFieldFlag(new GetFieldsName(getName()).getFields(),
- READONLY, true);
- setFieldFlag(new String[]{"closereason"}, READONLY, false);
- if ("提交".equals(getString("fstatus"))) {
- setFieldFlag("freturnmsg", READONLY, false);
- setFieldFlag("fprojectnotes", READONLY, false);
- setFieldFlag("fsaletype", READONLY, false);
- setFieldFlag("fnotes", READONLY, false);
- setFieldFlag("freviewtype", READONLY, false);
- }
- if ("审核".equals(getString("fstatus"))) {
- setFieldFlag("fnotes", READONLY, false);
- }
- } else {
- if ("促销订单".equals(getString("ftype"))) {
- //新建状态下促销类型为打包促销且没有生成配送方案的前提下,打包数量可编辑,否则为只读
- if ("打包促销".equals(getString("tpromotions.ftype")) && getPaoSet("saorderdetail_view2").isEmpty()) {
- setFieldFlag("fpromqty", READONLY, false);
- setFieldFlag("fpromqty", REQUIRED, true);
- } else {
- setFieldFlag("fpromqty", READONLY, true);
- setFieldFlag("fpromqty", REQUIRED, false);
- }
- }
- if ("02".equals(getString("faccclsnum"))) {
- setFieldFlag("fisusefl", READONLY, true);
- }
- if ("特殊订单".equals(getString("ftype"))) {
- setFieldFlag("ftypemx", READONLY, false);
- } else {
- setFieldFlag("ftypemx", READONLY, true);
- }
- if (!getPaoSet("saorderdetail_view").isEmpty()) {
- setFieldFlag(new String[]{"ftypemx", "fagentnum", "ftype", "fpromnum", "faccclsnum", "fprojectnum", "fbrand", "fborrowtype"}, READONLY, true);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public void canDelete() throws P2Exception {
- super.canDelete();
- if (!"新建".equals(getString("fstatus"))) {
- throw new P2AppException("", "非新建状态下不可删除");
- }
- if (getInt("fsourceid") > 0 && getOwner() == null) {
- throw new P2AppException("", "该订单由其他单据生成,不可删除");
- }
- }
- public boolean tobedelete = false;
- @Override
- public void delete(long l) throws P2Exception {
- canDelete();
- tobedelete = true;
- setValue("fstatus", "删除", 11L);
- setValue("description", "删除信息:" + getUserName() + "," + getDateTime_Str(), 11L);
- }
- @Override
- public void add() throws P2Exception {
- super.add();
- setValue("fsonum", createSoNum(), 11L);
- try {
- String app = getThisPaoSet().getApp();
- if ("SAORDER1".equalsIgnoreCase(app)) {
- setValue("ftype", "标准订单", 11L);
- }
- if ("SAORDER0".equalsIgnoreCase(app)) {
- setValue("ftype", "特殊订单", 11L);
- }
- if ("SAORDER01".equalsIgnoreCase(app)) {
- setValue("ftype", "工具订单", 11L);
- }
- if ("SAORDER02".equalsIgnoreCase(app)) {
- setValue("ftype", "项目订单", 11L);
- }
- if ("SAORDER2".equalsIgnoreCase(app)) {
- setValue("ftype", "特殊订单", 11L);
- }
- if ("SAORDER4".equalsIgnoreCase(app)) {
- setValue("ftype", "促销订单", 11L);
- }
- if ("SAORDER5".equalsIgnoreCase(app)) {
- setValue("ftype", "定制订单", 11L);
- }
- if ("SAORDER6".equalsIgnoreCase(app)) {
- setValue("ftype", "工具订单", 11L);
- }
- if ("SAORDER7".equalsIgnoreCase(app)) {
- setValue("ftype", "工具借出单", 11L);
- setValue("faccclsnum", "05", 11L);
- }
- if ("SAORDER8".equalsIgnoreCase(app)) {
- setValue("ftype", "工具借出单", 11L);
- setValue("faccclsnum", "05", 11L);
- }
- if ("SAORDER9".equalsIgnoreCase(app)) {
- setValue("ftype", "项目订单", 11L);
- }
- if ("SAORDER1".equalsIgnoreCase(app) || "SAORDER4".equalsIgnoreCase(app) || "SAORDER5".equalsIgnoreCase(app) || "SAORDER6".equalsIgnoreCase(app) || "SAORDER7".equalsIgnoreCase(app) || "SAORDER9".equalsIgnoreCase(app)) {
- String fagentnum = getAgentnumByHrid(getUserName());
- if (fagentnum != null) {
- setValue("fagentnum", fagentnum);
- }
- } else {
- //工厂做的单子
- setValue("createflag", true);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @Override
- public boolean toBeDeleted() {
- return super.toBeDeleted();
- }
- @Override
- protected void save() throws P2Exception {
- super.save();
- if (!toBeDeleted() && !tobedelete) {
- if ("".equals(getString("fagentnum"))) {
- throw new P2AppException("", "没有指定经销商");
- }
- if (toBeAdded()) {
- if ("".equals(getString("fsonum"))) {
- setValue("fsonum", createSoNum(), 11L);
- }
- }
- PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view");
- if ("".equals(getString("fpayagentnum"))) {
- setValue("fpayagentnum", getString("fagentnum"), 11L);
- }
- if ("".equals(getString("frecagentnum"))) {
- setValue("frecagentnum", getString("fagentnum"), 11L);
- }
- if (!toBeAdded() || (toBeAdded() && !saorderdetail_view.isEmpty())) {
- /**
- * 满减计算,满赠预计算
- */
- if ("新建".equals(getString("fstatus"))) {
- if (!"提交".equals(getPaoField("fstatus").getPreviousValue().asString())) {
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail_view");
- ordercaculate(saorderdetail);
- /**
- * 是否免运费计算
- */
- isFreeFreightCaculate();
- }
- }
- }
- }
- }
- public void ordercaculate(PaoSetRemote saorderdetail) throws P2Exception {
- //订单商品总金额
- double ftotalamount = saorderdetail.sum("famount");
- //满减计算
- caculateMJ(saorderdetail);
- //订单满减后金额
- ftotalamount = Math.sub(ftotalamount, saorderdetail.sum("fmjamount"));
- //开始将折后总金额分摊到商品折后金额中
- if (ftotalamount > 0 && !"工具借出单".equals("ftype")) {
- //订单返利金使用金额
- double fuseflamount = caculateUseFLAmount(ftotalamount);
- double fagentuseflamount = getDouble("fagentuseflamount");//经销商设置的返利金使用金额
- if (fuseflamount > 0 && fagentuseflamount > 0 && fagentuseflamount < fuseflamount) {
- fuseflamount = fagentuseflamount;
- setValue("fuseflamount", fuseflamount, 11L);
- setValue("fuseflrate", fuseflamount / ftotalamount, 11L);
- } else {
- setValue("fuseflamount", fuseflamount, 11L);
- }
- shareCaculate(saorderdetail, ftotalamount, fuseflamount);
- }
- //满赠计算
- caculateMZ_justcaculate();
- }
- /**
- * 折后分摊计算
- *
- * @throws P2Exception
- */
- public void shareCaculate(PaoSetRemote saorderdetail, double ftotalamount, double fuseflamount) throws P2Exception {
- if (fuseflamount >= 0) {
- double frowflamount = 0;
- int n = 0;
- PaoRemote detailpao = null;
- PaoRemote lastdetailpao = null;
- while ((detailpao = saorderdetail.getPao(n)) != null) {
- if (!detailpao.toBeDeleted()) {
- double fqty = detailpao.getDouble("fqty");
- if (fqty != 0) {
- double fdetailamount = detailpao.getDouble("famount");
- double fmjamount = detailpao.getDouble("fmjamount");
- double fdetailflamount = Math.mul(Math.div(Math.sub(fdetailamount, fmjamount), ftotalamount), fuseflamount, 2);
- detailpao.setValue("fflamount", fdetailflamount, 2L);
- frowflamount = Math.add(frowflamount, fdetailflamount);
- lastdetailpao = detailpao;
- }
- }
- n++;
- }
- /**
- * 余数计算,满减额度分配过程中如果出现余数,将此数在最后个匹配的行上进行补齐。
- */
- double yu = Math.sub(frowflamount, fuseflamount);
- if (yu != 0) {
- lastdetailpao.setValue("fflamount", Math.sub(lastdetailpao.getDouble("fflamount"), yu), 2L);
- }
- }
- }
- /**
- * 从物料档案添加物料
- *
- * @param itemset 物料档案表
- * @throws P2Exception
- */
- public void additems(PaoSetRemote itemset) throws P2Exception {
- Vector<PaoRemote> v = itemset.getSelection();
- if (v.size() > 100) {
- throw new P2AppException("", "商品添加,不可一次超过100件商品");
- }
- PaoSetRemote SAORDERDETAIL = getPaoSet("saorderdetail_view");
- String ftype = getString("ftype");
- if ("标准订单".equals(ftype)) {
- Iterator<PaoRemote> it = v.iterator();
- //开始遍历勾选的物料
- while (it.hasNext()) {
- titem selectpao = (titem) it.next();
- if (selectpao.getDouble("fsaleprice") <= 0) {
- //如果经销商端出现金额小于0 的情况,则直接跳过。
- continue;
- }
- //添加数量,如果数量为0,则自动变为1
- double faddqty = selectpao.getDouble("faddqty");
- faddqty = faddqty == 0 ? 1 : faddqty;
- int i = 0;
- //isnotalreadyhave判断物料是否不存在
- boolean isnotalreadyhave = true;
- PaoRemote detailpao = null;
- while ((detailpao = SAORDERDETAIL.getPao(i)) != null) {
- if (detailpao.getString("fitemno").equals(
- selectpao.getString("fitemno")) && !detailpao.toBeDeleted()) {
- //如果匹配上了,则表示物料已存在,将该值设为false
- isnotalreadyhave = false;
- double fqty = detailpao.getDouble("fqty");
- double fnewqty = fqty + faddqty;
- detailpao.setValue("fqty", fnewqty);
- break;
- }
- i++;
- }
- //如果物料不存在,则新增订单行
- if (isnotalreadyhave) {
- detailpao = SAORDERDETAIL.addAtEnd();
- detailpao.setValue("fitemno",
- selectpao.getString("fitemno"));
- detailpao.setValue("fqty", selectpao.getDouble("faddqty"));
- }
- }
- } else if ("定制订单".equals(ftype)) {
- Iterator<PaoRemote> it = v.iterator();
- //开始遍历勾选的物料
- while (it.hasNext()) {
- PaoRemote selectpao = it.next();
- if (selectpao.getDouble("fsaleprice") <= 0) {
- //如果经销商端出现金额小于0 的情况,则直接跳过。
- continue;
- }
- //添加数量,如果数量为0,则自动变为1
- double faddqty = selectpao.getDouble("faddqty");
- faddqty = faddqty == 0 ? 1 : faddqty;
- int i = 0;
- //isnotalreadyhave判断物料是否不存在
- boolean isnotalreadyhave = true;
- PaoRemote detailpao = null;
- while ((detailpao = SAORDERDETAIL.getPao(i)) != null) {
- if (detailpao.getString("fitemno").equals(
- selectpao.getString("fitemno"))) {
- //如果匹配上了,则表示物料已存在,将该值设为false
- isnotalreadyhave = false;
- double fqty = detailpao.getDouble("fqty");
- double fnewqty = fqty + faddqty;
- detailpao.setValue("fqty", fnewqty);
- break;
- }
- i++;
- }
- //如果物料不存在,则新增订单行
- if (isnotalreadyhave) {
- detailpao = SAORDERDETAIL.addAtEnd();
- detailpao.setValue("fitemno",
- selectpao.getString("fitemno"));
- detailpao.setValue("fqty", selectpao.getDouble("faddqty"));
- detailpao.setValue("fprice",
- selectpao.getDouble("fsaleprice"));
- detailpao.setValue("foldprice",
- selectpao.getDouble("fsaleprice"));
- }
- }
- } else {
- String[] fromfields = {"fitemno", "faddqty"};
- String[] tofields = {"fitemno", "fqty"};
- BatchAdd(itemset, fromfields, SAORDERDETAIL, tofields, true);
- }
- this.getThisPaoSet().save();
- }
- /**
- * 从促销方案添加物料
- *
- * @param itemset 物料档案表
- * @throws P2Exception
- */
- public void additems_prom(PaoSetRemote itemset) throws P2Exception {
- Vector<PaoRemote> v = itemset.getSelection();
- PaoSetRemote SAORDERDETAIL = getPaoSet("saorderdetail_view");
- Iterator<PaoRemote> it = v.iterator();
- //开始遍历勾选的物料
- while (it.hasNext()) {
- PaoRemote selectpao = it.next();
- if (selectpao.getDouble("fsaleprice") <= 0) {
- //如果经销商端出现金额小于0 的情况,则直接跳过。
- continue;
- }
- //添加数量,如果数量为0,则自动变为1
- double faddqty = selectpao.getDouble("faddqty");
- faddqty = faddqty == 0 ? 1 : faddqty;
- int i = 0;
- //isnotalreadyhave判断物料是否不存在
- boolean isnotalreadyhave = true;
- PaoRemote detailpao = null;
- while ((detailpao = SAORDERDETAIL.getPao(i)) != null) {
- if (detailpao.getString("fitemno").equals(
- selectpao.getString("fitemno")) && !detailpao.toBeDeleted()) {
- //如果匹配上了,则表示物料已存在,将该值设为false
- isnotalreadyhave = false;
- double fqty = detailpao.getDouble("fqty");
- double fnewqty = 0;
- if ("打包促销".equals(getString("tpromotions.ftype"))) {
- fnewqty = faddqty;
- } else {
- fnewqty = fqty + faddqty;
- }
- detailpao.setValue("fqty", fnewqty, 2L);
- break;
- }
- i++;
- }
- //如果物料不存在,则新增订单行
- if (isnotalreadyhave) {
- detailpao = SAORDERDETAIL.addAtEnd();
- detailpao.setValue("fitemno",
- selectpao.getString("fitemno"));
- detailpao.setValue("fqty", selectpao.getDouble("faddqty"), 2L);
- detailpao.setValue("fprice",
- selectpao.getDouble("fsaleprice"));
- detailpao.setValue("foldprice",
- selectpao.getDouble("foldsaleprice"));
- }
- }
- }
- /**
- * 从促销方案添加物料
- *
- * @param selectpao 物料档案表
- * @throws P2Exception
- */
- public PaoRemote additems_prom(PaoRemote selectpao) throws P2Exception {
- PaoSetRemote SAORDERDETAIL = getPaoSet("saorderdetail_view");
- //开始遍历勾选的物料
- if (selectpao.getDouble("fsaleprice") <= 0) {
- //如果经销商端出现金额小于0 的情况,则直接跳过。
- return null;
- }
- //添加数量,如果数量为0,则自动变为1
- double faddqty = selectpao.getDouble("faddqty");
- faddqty = faddqty == 0 ? 1 : faddqty;
- int i = 0;
- //isnotalreadyhave判断物料是否不存在
- boolean isnotalreadyhave = true;
- PaoRemote detailpao = null;
- while ((detailpao = SAORDERDETAIL.getPao(i)) != null) {
- if (detailpao.getString("fitemno").equals(
- selectpao.getString("fitemno")) && !detailpao.toBeDeleted()) {
- //如果匹配上了,则表示物料已存在,将该值设为false
- isnotalreadyhave = false;
- double fqty = detailpao.getDouble("fqty");
- double fnewqty = 0;
- if ("打包促销".equals(getString("tpromotions.ftype"))) {
- fnewqty = faddqty;
- } else {
- fnewqty = fqty + faddqty;
- }
- detailpao.setValue("fqty", fnewqty, 2L);
- break;
- }
- i++;
- }
- //如果物料不存在,则新增订单行
- if (isnotalreadyhave) {
- detailpao = SAORDERDETAIL.addAtEnd();
- detailpao.setValue("fitemno",
- selectpao.getString("fitemno"));
- detailpao.setValue("fqty", selectpao.getDouble("faddqty"), 2L);
- detailpao.setValue("fprice",
- selectpao.getDouble("fsaleprice"));
- detailpao.setValue("foldprice",
- selectpao.getDouble("foldsaleprice"));
- }
- return detailpao;
- }
- // @Override
- // public void confirmvalidate(boolean isconfirm) throws P2Exception {
- //
- // super.confirmvalidate(isconfirm);
- // //订单表体,所有
- // PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- // //订单表体,除配送件外
- // PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view");
- // //订单提交验证
- // if (isconfirm) {
- // if (!"新建".equals(getString("fstatus"))) {
- // throw new P2AppException("", "新建状态才可进行订单确认");
- // }
- // //经销商下单不允许出现金额为0的订单,配送件除外
- // if (getPaoSet("saorderdetail_view").min("fprice") < 0) {
- // throw new P2AppException("", "商品单价小于0,请删除该商品后重新添加");
- // }
- // if (saorderdetail.isEmpty()) {
- // throw new P2AppException("", "订单明细为空不可提交");
- // }
- // //非赠品商品数量不可等于0
- // if (saorderdetail_view.min("fqty") <= 0) {
- // throw new P2AppException("", "商品数量不可小于等于0");
- // }
- //
- // //配送方案是否生成验证
- // StringBuffer sql = new StringBuffer("");
- // sql.append("select t2.frownum,t2.fitemno from saorder t1 ");
- // sql.append("inner join saorderdetail t2 on t1.saorderid=t2.fparentid ");
- // sql.append("inner join titem t3 on t2.fitemno=t3.fitemno ");
- // sql.append("inner join titem_ration t4 on t3.fitemno=t4.fitemno ");
- // sql.append("inner join tration t5 on t4.frationnum=t5.frationnum ");
- // sql.append("where t1.fsonum='" + getString("fsonum") + "' and t2.fisration=0 and t3.fisrationmag=1 ");
- // sql.append("and t5.fstatus='审核' ");
- // sql.append("and (t5.fagentauthors=1 or exists(select *from tagents_ration where frationnum=t5.frationnum and fagentnum=t1.fagentnum))");
- // if ("标准订单".equals(getString("ftype"))) {
- // sql.append("and t5.fordertype1=1 ");
- // } else if ("特殊订单".equals(getString("ftype"))) {
- // sql.append("and t5.fordertype2=1 ");
- // } else if ("促销订单".equals(getString("ftype"))) {
- // sql.append("and t5.fordertype3=1 ");
- // } else if ("定制订单".equals(getString("ftype"))) {
- // sql.append("and t5.fordertype4=1 ");
- // } else {
- // sql.append("and 1=2");
- // }
- // ArrayList<HashMap<String, Object>> list = runQuerySQL(sql.toString());
- // if (!list.isEmpty() && getPaoSet("saorderdetail_view2").isEmpty()) {
- // int frownum = (int) list.get(0).get("frownum");
- // String fitemno = (String) list.get(0).get("fitemno");
- // throw new P2AppException("", "行" + frownum + "商品编号:" + fitemno + "存在配送方案,请选择配送方案后生成生成配送明细");
- // }
- // } else {
- // //订单退回验证
- // if (!"确认".equals(getString("fstatus"))) {
- // throw new P2AppException("", "非确认状态下不可退回");
- // }
- // }
- //
- // }
- // @Override
- // public void confirm(boolean isconfirm) throws P2Exception {
- //
- // super.confirm(isconfirm);
- //
- // if (isconfirm) {
- // /*单据状态变更*/
- // setValue("fstatus", "确认", 11L);
- // setValue("confirmby", getUserName(), 11L);
- // setValue("confirmdate", getDateTime(), 11L);
- //
- //
- // //微信消息推送
- // StringBuffer fcontent = new StringBuffer();
- // fcontent.append("您好,您有订单号为:").append(getString("fsonum")).append("的特殊订单,订单总金额:").append(
- // getDouble("saorder_totalview.famount")).append("请前往系统订单应用进行提交操作");
- // sendWechatMsg(getQyWechat(), fcontent.toString(), this);
- //
- //
- // } else {
- // /*单据状态变更*/
- // setValue("fstatus", "新建", 11L);
- // setValue("confirmby", "", 11L);
- // setValue("confirmdate", "", 11L);
- //
- //
- // /*退回微信消息推送*/
- // String fcontent = "尊敬的" + getString("fagentshortname")
- // + "经销商,您提交的订单号为" + getString("fsonum")
- // + "的特殊订单已被撤回。";
- // sendWechatMsg(getQyWechat(), fcontent, this);
- // }
- //
- // }
- /**
- * 检查商品价格是否变动
- */
- public HashMap<String, Double[]> checkitemprice() throws P2Exception {
- HashMap<String, Double[]> map = new HashMap<>();
- if (!"欠款发货".equals(getString("fborrowtype")) && !"特殊订单".equals(getString("ftype"))) {
- //订单表体,所有
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- int i = 0;
- while (saorderdetail.getPao(i) != null) {
- double order_foldprice = saorderdetail.getPao(i).getDouble("foldprice");
- double order_fsaleprice = saorderdetail.getPao(i).getDouble("fprice");
- PaoSetRemote titemset = saorderdetail.getPao(i).getPaoSet("titem");
- if (!titemset.isEmpty()) {
- titem titem = (titem) titemset.getPao(0);
- if (!saorderdetail.getPao(i).getBoolean("fpricechanged")) {
- //如果价格没有更改过,则进行价格判断
- double fsaleprice = titem.getAgentSalePrice(getString("fagentnum"));
- if (order_fsaleprice != fsaleprice) {
- map.put(titem.getString("fitemno"), new Double[]{order_fsaleprice, fsaleprice});
- }
- }
- if (!map.containsKey(titem.getString("fitemno"))) {
- /**
- * 销售价
- */
- double fprice = titem.getCardPriceByAagentnum(getString("fagentnum"));
- if (order_foldprice != fprice) {
- map.put(titem.getString("fitemno"), new Double[]{order_foldprice, fprice});
- }
- }
- }
- i++;
- }
- }
- return map;
- }
- /**
- * 更新商品价格
- */
- public void updateitemprice() throws P2Exception {
- HashMap<String, Double[]> map = new HashMap<>();
- //订单表体,所有
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail_view");
- int i = 0;
- while (saorderdetail.getPao(i) != null) {
- PaoSetRemote titemset = saorderdetail.getPao(i).getPaoSet("titem");
- if (!titemset.isEmpty()) {
- titem titem = (titem) titemset.getPao(0);
- /**
- * 牌价
- */
- double foldprice = titem.getCardPriceByAagentnum(getString("fagentnum"));
- /**
- * 销售价
- */
- double fprice = titem.getAgentSalePrice(getString("fagentnum"));
- saorderdetail.getPao(i).setValue("fprice", fprice);
- saorderdetail.getPao(i).setValue("frateprice", fprice);
- saorderdetail.getPao(i).setValue("foldprice", foldprice, 11L);
- }
- i++;
- }
- }
- /**
- * 提交验证
- *
- * @param issubmit 是否提交 true表示提交,false表示退回
- * @throws P2Exception
- */
- @Override
- public void submitvalidate(boolean issubmit) throws P2Exception {
- super.submitvalidate(issubmit);
- if ("".equals(getString("fsignbacknum"))) {
- if ("工具订单".equals(getString("ftype")) || "标准订单".equals(getString("ftype")) || "项目订单".equals(getString("ftype"))) {
- if(getSite().equals("HY")) {
- throw new P2AppException("", "回签单信息不可为空!");
- }
-
- }
- }
- if ("工具借出单".equals(getString("ftype"))) {
- submitvalidate_tools(issubmit);
- return;
- }
- //订单表体,所有
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- //订单表体,除配送件外
- PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view");
- //订单提交验证
- if (issubmit) {
- if (!"新建".equals(getString("fstatus"))) {
- throw new P2AppException("", "新建状态才可进行提交!");
- }
- {
- if ("".equals(getString("fphonenumber"))) {
- throw new P2AppException("", "联系方式不能为空");
- }
- if ("".equals(getString("fcontact"))) {
- throw new P2AppException("", "收货人不能为空");
- }
- if ("".equals(getString("faddress"))) {
- throw new P2AppException("", "收货地址不能为空");
- }
- if ("".equals(getString("finvoicename"))) {
- throw new P2AppException("", "开票单位不能为空");
- }
- if ("".equals(getString("finvoicetaxnumber"))) {
- throw new P2AppException("", "税号不能为空");
- }
- if ("".equals(getString("finvoiceaddress"))) {
- throw new P2AppException("", "开票地址不能为空");
- }
- if (saorderdetail_view.sum("fflamount") != getDouble("fuseflamount")) {
- throw new P2AppException("", "返利分摊金额计算错误!");
- }
- if (Math.sub(saorderdetail_view.sum("famount"), Math.add(saorderdetail_view.sum("fflamount"), saorderdetail_view.sum("fmjamount"))) != saorderdetail_view.sum("frateamount")) {
- throw new P2AppException("", "折后金额计算错误!");
- }
- }
- if (saorderdetail.isEmpty()) {
- throw new P2AppException("", "请至少添加一个商品");
- }
- //非赠品商品数量不可等于0
- if (saorderdetail_view.min("fqty") <= 0) {
- throw new P2AppException("", "商品数量不可小于等于0");
- }
- if ("标准订单".equals(getString("ftype")) && isLimitOrder()) {
- throw new P2AppException("", "您已被禁止订货");
- }
- if ("促销订单".equals(getString("ftype")) && isLimitOrder()) {
- throw new P2AppException("", "您已被禁止订货");
- }
- if ("项目订单".equals(getString("ftype"))) {
- if (getPaoSet("TPROJECT").isEmpty()) {
- throw new P2AppException("", "项目编号无效");
- }
- if (!"审核".equals(getPaoSet("TPROJECT").getPao(0).getString("fstatus"))) {
- throw new P2AppException("", "项目不在审核状态不可提交");
- }
- }
- //经销商下单不允许出现金额为0的订单,配送件除外
- if ("标准订单".equals(getString("ftype")) && !getBoolean("createflag")
- && getPaoSet("saorderdetail_view").min("fprice") <= 0) {
- throw new P2AppException("", "商品单价小于等于0,请删除该商品后重新添加");
- }
- //fissaleday
- int i = 0;
- while (saorderdetail.getPao(i) != null) {
- if (saorderdetail.getPao(i).getPaoSet("titem").getPao(0).getBoolean("fissaleday")) {
- if (saorderdetail.getPao(i).getString("fneeddate").equals("")) {
- throw new P2AppException("", "商品" + saorderdetail.getPao(i).getString("fitemname") + "交期管控,请填写交期");
- }
- }
- if ("样品".equals(getString("ftypemx"))) {
- if ("".equals(saorderdetail.getPao(i).getString("warehouse"))) {
- throw new P2AppException("", "样品订单需指定商品出库仓库");
- }
- }
- i++;
- }
- if ("促销订单".equals(getString("ftype"))) {
- PaoRemote tpromotion = getPaoSet("tpromotions").getPao(0);
- //活动结束日期
- Date fenddate = tpromotion.getDate("fenddate");
- //活动状态
- String fstatus = tpromotion.getString("fstatus");
- //活动起订量
- double fsaleminqty = tpromotion.getDouble("fsaleminqty");
- //活动起订金额
- double fsaleminamount = tpromotion.getDouble("fsaleminamount");
- if (fenddate.before(getDateTime())) {
- throw new P2AppException("", "促销活动已失效");
- }
- if (!"发布".equals(fstatus)) {
- throw new P2AppException("", "促销活动不在发布状态");
- }
- if ("打包促销".equals(getString("tpromotions.ftype")) && getDouble("fpromqty") <= 0) {
- throw new P2AppException("", "打包促销数量不可小于等于0");
- }
- if (saorderdetail_view.sum("fqty") < fsaleminqty) {
- throw new P2AppException("", "促销活动设置了起订量" + fsaleminqty + ",当前订单总数量不满足活动起订量");
- }
- if (saorderdetail_view.sum("famount") < fsaleminamount) {
- throw new P2AppException("", "促销活动设置了起订金额" + fsaleminamount + ",当前订单金额不满足活动起订金额");
- }
- //限量订购商品检验
- ArrayList<HashMap<String, Object>> list = runQuerySQL("select t1.fitemno,t1.fqty,t2.fsurplusqty from saorderdetail t1 inner join tpromproducts t2 on t1.fpromnum=t2.fpromnum and t1.fitemno=t2.fitemno where t2.fislimit=1 and t2.fsurplusqty<t1.fqty and t1.fsonum='" + getString("fsonum") + "'");
- if (!list.isEmpty()) {
- throw new P2AppException("", "商品编号" + list.get(0).get("fitemno") + "订购数量" + list.get(0).get("fqty") + "大于剩余可订购数量" + list.get(0).get("fsurplusqty"));
- }
- PaoSetRemote tpromagentSet = getPaoSet("tpromagents");
- if (!tpromagentSet.isEmpty()) {
- PaoRemote tpromagent = tpromagentSet.getPao(0);
- //是否限购
- if (tpromagent.getBoolean("fislimit")) {
- //限购类型
- String flimittype = tpromagent.getString("flimittype");
- //限购量
- double flimitvalue = tpromagent.getDouble("flimitvalue");
- //已购量
- double flimitvalue1 = tpromagent.getDouble("flimitvalue1");
- //订单总金额
- double ftotalamount = saorderdetail.sum("famount");
- if ("金额".equals(flimittype) && ftotalamount > Math.sub(flimitvalue, flimitvalue1)) {
- throw new P2AppException("", "您的订单总金额" + ftotalamount + "已超过剩余可订购金额" + Math.sub(flimitvalue, flimitvalue1));
- }
- }
- }
- }
- /*判断提交时是否需要进行扣款或账户冻结。如果需要则需进行账户可用余额的验证*/
- String fupdatebaltime = getSysVars().getString("fupdatebaltime");
- String fupdatfreeztime = getSysVars().getString("fupdatfreeztime");
- if ("订单提交".equals(fupdatebaltime) || "订单提交".equals(fupdatfreeztime)) {
- // 订单折后总额
- double frateamount = saorderdetail_view.sum("frateamount");
- //由于返利金使用额度是提交时临时计算,故不需要专门验证返利金的账户余额
- PaoSetRemote taccbal_view = getPaoSet("taccbal_view");
- //账户可用余额
- double fcanuseamount = taccbal_view.getPao(0).getDouble("fcanuseamount");
- //如果可用余额小于当前订单金额,则提示账户余额不足
- if (fcanuseamount < frateamount) {
- throw new P2AppException("", "账户可用余额不足");
- }
- }
- boolean haveRation = false;
- //配送方案是否生成验证
- StringBuffer sql = new StringBuffer();
- sql.append("select t2.frownum,t2.fitemno from saorder t1 ");
- sql.append("inner join saorderdetail t2 on t1.saorderid=t2.fparentid ");
- sql.append("inner join titem t3 on t2.fitemno=t3.fitemno and t2.siteid=t3.siteid ");
- sql.append("inner join titem_ration t4 on t3.fitemno=t4.fitemno and t2.siteid and t4.siteid ");
- sql.append("inner join tration t5 on t4.frationnum=t5.frationnum and t4.siteid=t5.siteid ");
- sql.append("where t1.fsonum='" + getString("fsonum") + "' and t1.siteid='" + getString("siteid") + "' and t2.fisration=0 and t3.fisrationmag=1 ");
- sql.append("and t5.fstatus='审核' ");
- sql.append("and (t5.fagentauthors=1 or exists(select *from tagents_ration where frationnum=t5.frationnum and fagentnum=t1.fagentnum)) ");
- if ("标准订单".equals(getString("ftype"))) {
- sql.append("and t5.fordertype1=1 ");
- } else if ("特殊订单".equals(getString("ftype"))) {
- sql.append("and t5.fordertype2=1 ");
- } else if ("促销订单".equals(getString("ftype"))) {
- sql.append("and t5.fordertype3=1 ");
- } else if ("定制订单".equals(getString("ftype"))) {
- sql.append("and t5.fordertype4=1 ");
- } else {
- sql.append("and 1=2 ");
- }
- ArrayList<HashMap<String, Object>> list = runQuerySQL(sql.toString());
- if (!list.isEmpty() && getPaoSet("saorderdetail_view2").isEmpty()) {
- int frownum = (int) list.get(0).get("frownum");
- String fitemno = (String) list.get(0).get("fitemno");
- throw new P2AppException("", "行" + frownum + "商品编号:" + fitemno + "存在配送方案,请选择配送方案后生成生成配送明细");
- }
- if (!getBoolean("createflag")) {
- //商品下架验证
- StringBuffer sql2 = new StringBuffer();
- sql2.append("select t2.frownum,t2.fitemno from saorder t1 ");
- sql2.append("inner join saorderdetail t2 on t1.saorderid=t2.fparentid ");
- sql2.append("inner join titem t3 on t2.fitemno=t3.fitemno and t2.siteid=t3.siteid ");
- sql2.append("where t1.fsonum='" + getString("fsonum") + "' and t1.siteid='" + getString("siteid") + "' and t3.fisonsale=0 and t1.ftype !='特殊订单'");
- ArrayList<HashMap<String, Object>> list2 = runQuerySQL(sql2.toString());
- if (!list2.isEmpty()) {
- int frownum = (int) list2.get(0).get("frownum");
- String fitemno = (String) list2.get(0).get("fitemno");
- throw new P2AppException("", "行" + frownum + "商品编号:" + fitemno + "已下架!");
- }
- }
- } else {
- //订单退回验证
- if (!"提交".equals(getString("fstatus"))) {
- throw new P2AppException("", "非提交状态下不可退回");
- }
- if ("SAORDER0".equalsIgnoreCase(getThisPaoSet().getApp()) && "".equals(getString("freturnmsg"))) {
- throw new P2AppException("", "退回原因不可为空");
- }
- }
- }
- /**
- * 提交验证
- *
- * @param issubmit 是否提交 true表示提交,false表示退回
- * @throws P2Exception
- */
- private void submitvalidate_tools(boolean issubmit) throws P2Exception {
- super.submitvalidate(issubmit);
- //订单表体,所有
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- //订单表体,除配送件外
- PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view");
- //订单提交验证
- if (issubmit) {
- if (!"新建".equals(getString("fstatus"))) {
- throw new P2AppException("", "新建状态才可进行提交!");
- }
- {
- if ("".equals(getString("fphonenumber"))) {
- throw new P2AppException("", "联系方式不能为空");
- }
- if ("".equals(getString("fcontact"))) {
- throw new P2AppException("", "收货人不能为空");
- }
- if ("".equals(getString("faddress"))) {
- throw new P2AppException("", "收货地址不能为空");
- }
- }
- if (saorderdetail.isEmpty()) {
- throw new P2AppException("", "请至少添加一个商品");
- }
- //非赠品商品数量不可等于0
- if (saorderdetail_view.min("fqty") <= 0) {
- throw new P2AppException("", "商品数量不可小于等于0");
- }
- if (isLimitOrder()) {
- throw new P2AppException("", "您已被禁止订货");
- }
- } else {
- //订单退回验证
- if (!"提交".equals(getString("fstatus"))) {
- throw new P2AppException("", "非提交状态下不可退回");
- }
- if ("SAORDER0".equalsIgnoreCase(getThisPaoSet().getApp()) && "".equals(getString("freturnmsg"))) {
- throw new P2AppException("", "退回原因不可为空");
- }
- }
- }
- public void changesalervalidate() throws P2Exception {
- }
- public void changesaler() throws P2Exception {
- setFieldFlag("fsaler", READONLY, false);
- }
- /**
- * 提交
- *
- * @param issubmit
- * @throws P2Exception
- */
- @Override
- public void submit(boolean issubmit) throws P2Exception {
- super.submit(issubmit);
- if ("工具借出单".equals(getString("ftype"))) {
- submit_tools(issubmit);
- return;
- }
- /**
- * 订单指定账户
- */
- taccbal taccbal = null;
- PaoSetRemote taccbalSet = getPaoSet("taccbal");
- if (taccbalSet.isEmpty()) {
- taccbal = (taccbal) taccbalSet.addAtEnd();
- taccbal.setfields(getString("fpayagentnum"), getString("faccclsnum"));
- } else {
- taccbal = (taccbal) taccbalSet.getPao(0);
- }
- /**
- * 订单指定账户
- */
- taccbal taccbal_fl = null;
- PaoSetRemote taccbalSet_fl = getPaoSet("taccbal_fl");
- if (taccbalSet_fl.isEmpty()) {
- taccbal_fl = (taccbal) taccbalSet_fl.addAtEnd();
- taccbal_fl.setfields(getString("fpayagentnum"), "02");
- } else {
- taccbal_fl = (taccbal) taccbalSet_fl.getPao(0);
- }
- //系统参数表
- PaoRemote sysVars = getSysVars();
- /*获取系统参数*/
- //总仓库存可销售量扣减时机,
- String fupdateavlqtytime = sysVars.getString("fupdateavlqtytime");
- //订单扣款时机:订单提交、订单审核、销售出库单审核
- String fupdatebaltime = sysVars.getString("fupdatebaltime");
- //冻结金额时机:订单提交、订单审核
- String fupdatfreeztime = sysVars.getString("fupdatfreeztime");
- //订单提交自动审核的单据类型
- String forderautochecktype = getSysVars().getString("forderautochecktype");
- // 经销商参数是否需要提交自动审核
- boolean fsaorderautocheck = getPaoSet("tagents").getPao(0).getBoolean("fsaorderautocheck");
- //订单表体,包括辅材
- PaoSetRemote saorderdetailSet = getPaoSet("saorderdetail_view");
- // 订单指定账户扣款总额
- double ftotalrateamount = saorderdetailSet.sum("frateamount");
- // 订单使用返利总金额
- double fuseflamount = saorderdetailSet.sum("fflamount");
- //提交
- if (issubmit) {
- if ("促销订单".equals(getString("ftype"))) {
- updatePromotion(true);
- }
- if ("订单提交".equals(fupdatebaltime)) {
- /*如果系统参数设为为提交时扣款,则提交时需要生成支出凭证*/
- /*生成支出凭证*/
- String fnotes = "该单由销售订单" + getString("fsonum") + "提交时自动生成";
- /**
- * 生成返利支出凭证,如果返利金额为0,则不生成
- */
- createFicashbill_fl_Pay(taccbal_fl, fuseflamount, fnotes);
- /**
- * 生成账户支出凭证
- */
- createFicashbill_Pay(taccbal, ftotalrateamount, fnotes, true);
- } else if ("订单提交".equals(fupdatfreeztime)) {
- /*如果系统参数设为为提交时冻结金额,则提交时需要进行账户金额冻结*/
- /*账户余额冻结*/
- String fnotes = "由销售订单" + getString("fsonum") + "提交时冻结";
- updateTaccbal_freez(taccbal, ftotalrateamount, fnotes);
- }
- //总仓库存可销售量扣减
- if ("订单提交".equals(fupdateavlqtytime)) {
- //updateIcinvbal_total(false, false);
- }
- boolean isrowerr = getDistinctString(saorderdetailSet, "frownum", false).length != saorderdetailSet.count();
- //遍历订单表体
- int i = 0;
- saorderdetail detailpao = null;
- while ((detailpao = (saorderdetail) saorderdetailSet.getPao(i)) != null) {
- if (isrowerr) {
- detailpao.setValue("frownum", i + 1, 11L);
- }
- //重新计算产品的未发货数量
- detailpao.setValue("fundeliqty", detailpao.getDouble("fqty"), 11L);
- //如果是定制订单,则根据定制项生成定制信息
- if ("定制订单".equals(getString("ftype"))) {
- StringBuffer fcustomizedstr = new StringBuffer();
- PaoSetRemote saorder_customizedSet = detailpao.getPaoSet("saorder_customized");
- saorder_customizedSet.setOrderBy("SAORDER_CUSTOMIZID");
- int n = 0;
- PaoRemote saorder_customized = null;
- while ((saorder_customized = saorder_customizedSet.getPao(n)) != null) {
- fcustomizedstr.append(saorder_customized.getString("fname")).append(":").append(saorder_customized.getString("fvalue")).append(";");
- n++;
- }
- detailpao.setValue("fcustomizedstr", "{" + fcustomizedstr.toString() + "}", 11L);
- }
- i++;
- }
- /*单据状态变更*/
- setValue("fstatus", "提交", 11L);
- setValue("submitby", getUserName(), 11L);
- setValue("submitdate", getDateTime(), 11L);
- setValue("submitcount", getInt("submitcount") + 1, 11L);
- // 判断提交是否自动审核
- if (fsaorderautocheck && forderautochecktype.contains(getString("ftype"))) {
- boolean canCheck = true;
- if ("订单审核".equals(fupdatebaltime) || "订单审核".equals(fupdatfreeztime)) {
- // 如果系统参数设置订单审核扣款时,此时账户尚未进行扣款或冻结,
- // 审核前需验证账户余额是否充足,如账户余额不足,则不允许自动审核。
- // 通过经销商账户余额查询视图获取账户可用余额
- double fcanuseamount = getPaoSet("taccbal_view").getPao(0).getDouble("fcanuseamount");
- if (fcanuseamount < ftotalrateamount) {
- //如果账户可用余额小于当前订单金额,则不允许自动审核。
- canCheck = false;
- }
- }
- //如果已在订单提交时金扣款或冻结,或者账户余额充足,则当前订单自动审核
- if (canCheck) {
- check(true);
- }
- }
- //微信消息推送
- StringBuffer fcontent = new StringBuffer();
- fcontent.append("您好,您的订单号为:").append(getString("fsonum")).append("的").append(
- getString("ftype")).append("已提交,订单总金额:").append(
- getDouble("saorder_totalview.famount"));
- sendWechatMsg(getQyWechat(), fcontent.toString(), this);
- /**
- * 如果是交期管控的,且库存不足的,则进行邮件提醒
- */
- if (issaleday() && !checkStockStatus()) {
- //交期回复提醒
- sendEmail(getMailByHrGroup(getString("siteid") + "1005"), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交,需要进行交期回复", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交待交期回复;订单号:" + getString("fsonum"));
- }
- //销管订单提交待审核邮件提醒
- sendEmail(getMailByHrGroup(getString("siteid") + "1001"), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交待审", "【订单领域】" + getString("fieldname") + ",【订单提交待审核】订单号:" + getString("fsonum") + "(订单客户:" + getString("FAGENTSHORTNAME") + ",备注:" + ("".equals(getString("fnotes")) ? "无" : getString("fnotes")) + ")已提交请审核;");
- //任务箱提醒
- createAssignment(getHrIdByHrGroup(getString("siteid") + "1001"), "SAORDER0", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交待审", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交待审;订单号:" + getString("fsonum"));
- } else {
- deleteAssignment();
- if ("促销订单".equals(getString("ftype"))) {
- updatePromotion(false);
- }
- /*退回操作*/
- /*资金账户计算*/
- if ("订单提交".equals(fupdatebaltime)) {
- /*如果系统参数设为为提交时扣款,则退回时需要生成负数的支出凭证*/
- /*生成支出凭证*/
- String fnotes = "该单由销售订单" + getString("fsonum") + "退回时自动生成";
- //PaoSetRemote ficashbillset = getPaoSet("$ficashbill_fl", "ficashbill", "ftypemx='返利金' and ftype='支出' and fstatus='审核' and fsourceobject='SAORDER' and fsourceid=" + getUniqueIDValue());
- //返利不退
- //createFicashbill_fl_Pay(taccbal_fl, -famount_fl, fnotes);
- //createFicashbill_Pay(taccbal, -(Math.sub(ftotalamount, fuseflamount)), fnotes, true);
- createFicashbill_fl_Pay(taccbal_fl, -fuseflamount, fnotes);
- createFicashbill_Pay(taccbal, -ftotalrateamount, fnotes, true);
- } else if ("订单提交".equals(fupdatfreeztime)) {
- /*如果系统参数设为为提交时冻结账户余额,则退回时需要进行账户余额的解冻*/
- deleteTaccbal_freez();
- }
- /*库存计算*/
- //总仓库存可销售量扣减
- if ("订单提交".equals(fupdateavlqtytime)) {
- //如果系统参数设为提交时进行可销售数量的扣减,则退回时需要将订单数量返回到库存的可销售数量中。
- //updateIcinvbal_total(true, false);
- }
- /*单据状态变更*/
- setValue("fstatus", "新建", 11L);
- setValue("submitby", "", 11L);
- setValue("submitdate", "", 11L);
- setValue("fnotes", getString("fnotes") + "----订单退回", 11L);
- /*退回微信消息推送*/
- String fcontent = "尊敬的" + getString("fagentshortname")
- + "经销商,您提交的订单号为" + getString("fsonum")
- + "的订单审核不通过,请登录系统查询。";
- sendWechatMsg(getQyWechat(), fcontent, this);
- }
- }
- /**
- * 工具借出申请单提交
- *
- * @param issubmit
- * @throws P2Exception
- */
- private void submit_tools(boolean issubmit) throws P2Exception {
- super.submit(issubmit);
- if (issubmit) {
- /*单据状态变更*/
- setValue("fstatus", "提交", 11L);
- setValue("submitby", getUserName(), 11L);
- setValue("submitdate", getDateTime(), 11L);
- setValue("submitcount", getInt("submitcount") + 1, 11L);
- /**
- * 如果是交期管控的,且库存不足的,则进行邮件提醒
- */
- if (issaleday() && !checkStockStatus()) {
- //交期回复提醒
- sendEmail(getMailByHrGroup(getString("siteid") + "1005"), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交,需要进行交期回复", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》提交待交期回复;订单号:" + getString("fsonum"));
- }
- //销管订单提交待审核邮件提醒
- sendEmail(getMailByHrGroup(getString("siteid") + "1001"), getString("fagentshortname") + "工具借出单提交待审", getString("FAGENTSHORTNAME") + "订单提交待审;订单号:" + getString("fsonum"));
- //任务箱提醒
- createAssignment(getHrIdByHrGroup(getString("siteid") + "1001"), "SAORDER0", getString("FAGENTSHORTNAME") + "工具借出单提交待审", getString("FAGENTSHORTNAME") + "工具借出单提交待审;单号:" + getString("fsonum"));
- } else {
- deleteAssignment();
- setValue("fstatus", "新建", 11L);
- setValue("submitby", "", 11L);
- setValue("submitdate", "", 11L);
- setValue("fnotes", getString("fnotes") + "----订单退回", 11L);
- }
- }
- /**
- * 交期回复验证
- */
- public void needdatereplyvalidate(boolean isneeddatereply) throws P2Exception {
- if (isneeddatereply) {
- if (!"提交".equals(getString("fstatus"))) {
- throw new P2AppException("", "非提交状态下不可进行交期回复");
- }
- //订单表体,所有商品信息,包括辅材配件
- if (issaleday()) {
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- int i = 0;
- PaoRemote pao = null;
- while ((pao = saorderdetail.getPao(i)) != null) {
- if (pao.getPaoSet("titem").getPao(0).getBoolean("fissaleday")) {
- if ("".equals(pao.getString("fplandate"))) {
- throw new P2AppException("", "行" + pao.getInt("frownum") + "商品" + pao.getString("fitemname") + "为交期管控,请填写回复交期!");
- }
- }
- i++;
- }
- } else {
- throw new P2AppException("", "不存在交期管控的商品,无需进行交期回复,可直接进行订单审核");
- }
- } else {
- if (!"交期待确认".equals(getString("fstatus"))) {
- throw new P2AppException("", "非交期待确认状态下不可撤销交期回复");
- }
- }
- }
- /**
- * 交期回复
- */
- public void needdatereply(boolean isneeddatereply) throws P2Exception {
- if (isneeddatereply) {
- setValue("needdatereplydate", getDate(), 11L);
- setValue("needdatereplyby", getUserName(), 11L);
- setValue("fstatus", "交期待确认", 11L);
- {
- //业务员邮件提醒
- sendEmail(getMailByHrId(getString("fsaler")), getString("FAGENTSHORTNAME") + "交期待确认", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》交期待确认;订单号:" + getString("fsonum"));
- }
- } else {
- setValue("needdatereplydate", "", 11L);
- setValue("needdatereplyby", "", 11L);
- setValue("fstatus", "提交", 11L);
- }
- }
- /**
- * 交期确认验证
- */
- public void needdateconfirmvalidate(boolean isneeddateconfirm) throws P2Exception {
- if (isneeddateconfirm) {
- if (!"交期待确认".equals(getString("fstatus"))) {
- throw new P2AppException("", "非交期待确认状态下不可进行交期确认");
- }
- } else {
- if (!"交期确认".equals(getString("fstatus"))) {
- throw new P2AppException("", "非交期确认状态下不可撤销交期确认");
- }
- }
- }
- /**
- * 交期确认
- */
- public void needdateconfirm(boolean isneeddateconfirm) throws P2Exception {
- if (isneeddateconfirm) {
- setValue("needdateconfirmdate", getDate(), 11L);
- setValue("needdateconfirmby", getUserName(), 11L);
- setValue("fstatus", "交期确认", 11L);
- //销管订单提交待审核邮件提醒
- sendEmail(getMailByHrGroup(getString("siteid") + "1001"), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》交期确认待审", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》交期确认待审;订单号:" + getString("fsonum"));
- //任务箱提醒
- createAssignment(getHrIdByHrGroup(getString("siteid") + "1001"), "SAORDER0", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》交期确认待审", getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》交期确认待审;订单号:" + getString("fsonum"));
- } else {
- setValue("needdateconfirmdate", "", 11L);
- setValue("needdateconfirmby", "", 11L);
- setValue("fstatus", "交期待确认", 11L);
- }
- }
- /**
- * 检查订单是否需要交期管控
- *
- * @return
- */
- public boolean issaleday() throws P2Exception {
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- int i = 0;
- PaoRemote pao = null;
- while ((pao = saorderdetail.getPao(i)) != null) {
- if (pao.getPaoSet("titem").getPao(0).getBoolean("fissaleday")) {
- return true;
- }
- i++;
- }
- return false;
- }
- /**
- * 检查商品是否都上架
- *
- * @return
- */
- public String isnotonsaleitemnos() throws P2Exception {
- String fitemnos = "";
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- int i = 0;
- PaoRemote pao = null;
- while ((pao = saorderdetail.getPao(i)) != null) {
- if (!pao.getPaoSet("titem").getPao(0).getBoolean("fisonsale")) {
- if (fitemnos.equals("")) {
- fitemnos = pao.getString("fitemno");
- } else {
- fitemnos = fitemnos + "、" + pao.getString("fitemno");
- }
- }
- i++;
- }
- return fitemnos;
- }
- /**
- * @param fischeck 审核、反审核
- * @param fisman 是否人工审核
- * @throws P2Exception
- */
- public void checkvalidate(boolean fischeck, boolean fisman)
- throws P2Exception {
- if (fischeck) {
- DBConnect dbConnect = new DBConnect();
- Rows rows = dbConnect.runSqlQuery("select fitemno,fitemname from saorderdetail where fparentid='" + getUniqueIDValue() + "' and fplandate<getdate()");
- for (Row row : rows) {
- throw new P2AppException("", "商品" + row.getString("fitemno") + row.getString("fitemname from") + "回复交期已过期,不可审核!");
- }
- if ("NB".equals(getString("siteid")) && "".equals(getString("fsaletype"))) {
- throw new P2AppException("", "销售分类不可为空!");
- }
- if ("TZ".equals(getString("siteid")) && "".equals(getString("freviewtype"))) {
- throw new P2AppException("", "订单评审类型不可为空!");
- }
- }
- if ("工具借出单".equals(getString("ftype"))) {
- checkvalidate_tools(fischeck);
- return;
- }
- //系统参数表
- PaoRemote sysVars = getSysVars();
- //订单表体,所有商品信息,包括辅材配件
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- if (fischeck) {
- if (!"提交".equals(getString("fstatus")) && !"交期确认".equals(getString("fstatus"))) {
- throw new P2AppException("", "非提交或交期确认状态不可审核");
- }
- /*如果是审核时进行扣款,且时人工审核的则判断账户余额不足直接抛异常,如果是自动的,则自动任务会自动跳过*/
- String fupdatebaltime = getSysVars().getString("fupdatebaltime");
- String fupdatfreeztime = getSysVars().getString("fupdatfreeztime");
- if (fisman && ("订单审核".equals(fupdatebaltime) || "订单审核".equals(fupdatfreeztime))) {
- double ftotalamount = getPaoSet("saorderdetail").sum("famount");
- double fcanuseamount = getPaoSet("taccbal_view").getPao(0).getDouble("fcanuseamount");
- double freezamount = 0;
- if ("订单审核".equals(sysVars.getString("fdeletefreeztime"))) {
- PaoSetRemote taccbal_freez = getPaoSet("$taccbal_freez",
- "taccbal_freez", "fsourceobject='" + getName()
- + "' and fsourceid='" + getUniqueIDValue() + "'");
- if (!taccbal_freez.isEmpty()) {
- /**
- * 订单审核是需要解冻,需查出原订单冻结金额。防止账户余额不足引起审核失败
- */
- freezamount = taccbal_freez.sum("famount");
- }
- }
- //返利可用金额
- double fuseflamount = saorderdetail.sum("fflamount");
- if (Math.add(Math.add(fcanuseamount, freezamount), fuseflamount) < ftotalamount) {
- throw new P2AppException("", "账户可用余额不足");
- }
- }
- if ("HY".equals(getString("siteid")) || "TZ".equals(getString("siteid"))) {
- String fsaletype[] = {"标准订单", "促销订单", "工具订单", "特殊订单", "项目订单"};
- if (Arrays.asList(fsaletype).contains(getString("ftype"))) {
- if ("".equals(getString("fsaletype"))) {
- throw new P2AppException("", "请选择销售分类!");
- }
- }
- }
- if ("项目订单".equals(getString("ftype")) && !"审核".equals(getPaoSet("TPROJECT").getPao(0).getString("fstatus"))) {
- throw new P2AppException("", "项目不在审核状态不可审核");
- }
- } else {
- if (!"审核".equals(getString("fstatus"))) {
- throw new P2AppException("", "非审核状态不可反审核");
- }
- if (saorderdetail.sum("fqty") != saorderdetail.sum("fundeliqty")) {
- throw new P2AppException("", "已经发货,不可反审核");
- }
- if (!getPaoSet("icstockbilldetail").isEmpty()) {
- throw new P2AppException("", "存在销售出库单,不可反审核");
- }
- if (!getPaoSet("sainvoice").isEmpty()) {
- throw new P2AppException("", "存在发货单,不可反审核");
- }
- if (!getPaoSet("saorderdetail_close").isEmpty()) {
- throw new P2AppException("", "已存在关闭的行,不可反审核");
- }
- if (saorderdetail.sum("fwriteoffamount") != 0) {
- throw new P2AppException("", "核销金额不为0,不可反审核");
- }
- if (saorderdetail.sum("finvoiceamount") != 0) {
- throw new P2AppException("", "开票金额不为0,不可反审核");
- }
- }
- }
- /**
- * 工具借出单审核
- *
- * @param fischeck 审核、反审核
- * @throws P2Exception
- */
- public void checkvalidate_tools(boolean fischeck)
- throws P2Exception {
- //订单表体,所有商品信息,包括辅材配件
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- if (fischeck) {
- if (issaleday()) {
- if ((!"交期确认".equals(getString("fstatus")) && !"提交".equals(getString("fstatus"))) && !getBoolean("createflag")) {
- throw new P2AppException("", "存在交期管控商品,非提交或交期确认状态不可审核");
- }
- if (!"新建".equals(getString("fstatus")) && !"提交".equals(getString("fstatus")) && !"交期确认".equals(getString("fstatus")) && getBoolean("createflag")) {
- throw new P2AppException("", "非新建状态不可审核");
- }
- } else {
- if (!"提交".equals(getString("fstatus")) && !getBoolean("createflag")) {
- throw new P2AppException("", "非提交状态不可审核");
- }
- if (!"新建".equals(getString("fstatus")) && !"提交".equals(getString("fstatus")) && getBoolean("createflag")) {
- throw new P2AppException("", "非新建状态不可审核");
- }
- }
- } else {
- if (!"审核".equals(getString("fstatus"))) {
- throw new P2AppException("", "非审核状态不可反审核");
- }
- if (saorderdetail.sum("fqty") != saorderdetail.sum("fundeliqty")) {
- throw new P2AppException("", "已经发货,不可反审核");
- }
- if (!getPaoSet("icstockbilldetail").isEmpty()) {
- throw new P2AppException("", "存在销售出库单,不可反审核");
- }
- if (!getPaoSet("sainvoice").isEmpty()) {
- throw new P2AppException("", "存在发货单,不可反审核");
- }
- if (!getPaoSet("saorderdetail_close").isEmpty()) {
- throw new P2AppException("", "已存在关闭的行,不可反审核");
- }
- if (saorderdetail.sum("fwriteoffamount") != 0) {
- throw new P2AppException("", "核销金额不为0,不可反审核");
- }
- if (saorderdetail.sum("finvoiceamount") != 0) {
- throw new P2AppException("", "开票金额不为0,不可反审核");
- }
- }
- }
- @Override
- public void check(boolean fischeck) throws P2Exception {
- if ("工具借出单".equals(getString("ftype"))) {
- check_tools(fischeck);
- return;
- }
- if (fischeck && issaleday()) {
- PaoSetRemote saorderdetailSet = getPaoSet("saorderdetail");
- int i = 0;
- while (saorderdetailSet.getPao(i) != null) {
- if ("".equals(saorderdetailSet.getPao(i).getString("fplandate"))) {
- saorderdetailSet.getPao(i).setValue("fplandate", saorderdetailSet.getPao(i).getString("fneeddate"), 11L);
- }
- i++;
- }
- }
- /**
- * 订单指定账户
- */
- taccbal taccbal = null;
- PaoSetRemote taccbalSet = getPaoSet("taccbal");
- if (taccbalSet.isEmpty()) {
- taccbal = (taccbal) taccbalSet.addAtEnd();
- taccbal.setfields(getString("fpayagentnum"), getString("faccclsnum"));
- } else {
- taccbal = (taccbal) taccbalSet.getPao(0);
- }
- /**
- * 订单指定账户
- */
- taccbal taccbal_fl = null;
- PaoSetRemote taccbalSet_fl = getPaoSet("taccbal_fl");
- if (taccbalSet_fl.isEmpty()) {
- taccbal_fl = (taccbal) taccbalSet_fl.addAtEnd();
- taccbal_fl.setfields(getString("fpayagentnum"), "02");
- } else {
- taccbal_fl = (taccbal) taccbalSet_fl.getPao(0);
- }
- /**
- * 订单指定账户
- */
- taccbal taccbal_wl = null;
- PaoSetRemote taccbalSet_wl = getPaoSet("taccbal_wl");
- if (taccbalSet_wl.isEmpty()) {
- taccbal_wl = (taccbal) taccbalSet_wl.addAtEnd();
- taccbal_wl.setfields(getString("fpayagentnum"), "03");
- } else {
- taccbal_wl = (taccbal) taccbalSet_wl.getPao(0);
- }
- //系统参数表
- PaoRemote sysVars = getSysVars();
- //总仓库存可销售量扣减时机,
- String fupdateavlqtytime = sysVars.getString("fupdateavlqtytime");
- //订单账户管控是否扣款
- String fupdatebaltime = sysVars.getString("fupdatebaltime");
- //订单账户管控是否冻结金额
- String fupdatfreeztime = sysVars.getString("fupdatfreeztime");
- //订单账户管控是否解冻金额
- String fdeletefreeztime = sysVars.getString("fdeletefreeztime");
- //订单表体,包括辅材赠品
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- // 订单总额
- double ftotalamount = saorderdetail.sum("famount");
- // 订单指定账户扣款总额
- double ftotalrateamount = saorderdetail.sum("frateamount");
- // 订单使用返利总金额
- double fuseflamount = saorderdetail.sum("fflamount");
- if (fischeck) {
- deleteAssignment();
- /*资金账户计算*/
- if ("订单审核".equals(fupdatebaltime)) {
- /*如果系统参数设为为提交时扣款,则提交时需要生成支出凭证*/
- /*生成支出凭证*/
- String fnotes = "该单由销售订单" + getString("fsonum") + "审核时自动生成";
- /**
- * 生成返利支出凭证
- */
- createFicashbill_fl_Pay(taccbal_fl, fuseflamount, fnotes);
- /**
- * 生成账户支出凭证
- */
- createFicashbill_Pay(taccbal, ftotalrateamount, fnotes, true);
- } else if ("订单审核".equals(fupdatfreeztime)) {
- /*如果系统参数设为为提交时冻结金额,则提交时需要进行账户金额冻结*/
- /*账户余额冻结*/
- String fnotes = "由销售订单" + getString("fsonum") + "审核时冻结";
- updateTaccbal_freez(taccbal, ftotalrateamount, fnotes);
- }
- if ("订单审核".equals(fdeletefreeztime)) {
- deleteTaccbal_freez();
- }
- //总仓库存可销售量扣减
- if ("订单审核".equals(fupdateavlqtytime)) {
- // updateIcinvbal_total(false, false);
- }
- /**
- * 是否年度首单返利
- */
- boolean fisyearfirstorder_fl = fisyearfirstorder_fl(ftotalrateamount);
- //年度首笔订单返利
- PaoRemote tagent = getPaoSet("tagents").getPao(0);
- if (fisyearfirstorder_fl) {
- //年度首单返利比例
- double fisfirstorderflrate = tagent.getDouble("fisfirstorderflrate");
- createFicashbill_FL(taccbal_fl, "年度首单返利", "年度首单返利" + getString("fsonum"), ftotalrateamount * fisfirstorderflrate);
- }
- /**
- * 是否年度首单物料补贴
- */
- boolean fisyearfirstorder_wl = fisyearfirstorder_wl(ftotalrateamount);
- if (fisyearfirstorder_wl) {
- //年度首单物料补贴比例
- double fisfirstorderrate = tagent.getDouble("fisfirstorderrate");
- createFicashbill_WL(taccbal_wl, "年度首单补贴", "年度首单物料补贴" + getString("fsonum"), ftotalrateamount * fisfirstorderrate);
- }
- //满赠计算。
- if ("订单审核".equals(fupdatebaltime)) {
- caculateMZ(taccbal_wl, taccbal_fl, getDate());
- } else if ("订单提交".equals(fupdatebaltime)) {
- caculateMZ(taccbal_wl, taccbal_fl, getDate("submitdate"));
- }
- /******** 单据状态更新 ********/
- setValue("fstatus", "审核", 11L);
- setValue("checkby", getUserName(), 11L);
- setValue("checkdate", getDateTime(), 11L);
- // {
- // //业务员邮件提醒
- // // sendEmail(getMailByHrId(getString("fsaler")), getString("FAGENTSHORTNAME") + "订单已审核", getString("FAGENTSHORTNAME") + "订单已审核;订单号:" + getString("fsonum"));
- // try {
- // if ("NB".equals(getString("siteid"))) {
- // //业务员邮件提醒
- // sendReportByEmail(getMailByHrId(getString("fsaler")), "NB_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "订单已审核;订单号:" + getString("fsonum"));
- // //根据领域不同发送邮件给对应的小组
- // sendReportByEmail(getMailByHrGroup("NB1007", getString("fieldname")), "NB_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "订单已审核;订单号:" + getString("fsonum"));
- // } else if ("TZ".equals(getString("siteid"))) {
- // //业务员邮件提醒
- // sendReportByEmail(getMailByHrId(getString("fsaler")), "TZ_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "订单已审核;订单号:" + getString("fsonum"));
- // //根据领域不同发送邮件给对应的小组
- // sendReportByEmail(getMailByHrGroup("TZ1007", getString("fieldname")), "TZ_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "订单已审核;订单号:" + getString("fsonum"));
- // } else if ("HY".equals(getString("siteid"))) {
- // //业务员邮件提醒
- // sendReportByEmail(getMailByHrId(getString("fsaler")), "HY_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "订单已审核;订单号:" + getString("fsonum"));
- // //根据领域不同发送邮件给对应的小组
- // sendReportByEmail(getMailByHrGroup("HY1007", getString("fieldname")), "HY_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "订单已审核;订单号:" + getString("fsonum"));
- // }
- // } catch (Exception e) {
- // e.printStackTrace();
- // }
- // }
- } else {
- /*资金账户计算*/
- if ("订单审核".equals(fupdatebaltime)) {
- /*如果系统参数设为为订单审核时扣款,则反审核时需要生成负数的支出凭证*/
- /*生成支出凭证*/
- String fnotes = "该单由销售订单" + getString("fsonum") + "反审核时自动生成";
- createFicashbill_fl_Pay(taccbal_fl, -fuseflamount, fnotes);
- createFicashbill_Pay(taccbal, -ftotalrateamount, fnotes, true);
- } else if ("订单审核".equals(fupdatfreeztime)) {
- /*如果系统参数设为为审核时冻结账户余额,则反审核时需要进行账户余额的解冻*/
- deleteTaccbal_freez();
- }
- if ("订单审核".equals(fdeletefreeztime)) {
- /*如果系统参数设为订单审核时解冻账户余额,则反审核时需要进行账户余额的冻结*/
- String fnotes = "由销售订单" + getString("fsonum") + "审核时冻结";
- updateTaccbal_freez(taccbal, ftotalrateamount, fnotes);
- }
- //总仓库存可销售量扣减
- if ("订单审核".equals(fupdateavlqtytime)) {
- //updateIcinvbal_total(true, false);
- }
- /******** 单据状态更新 ********/
- setValue("fstatus", "提交", 11L);
- setValue("checkby", "", 11L);
- setValue("checkdate", "", 11L);
- }
- }
- public void sendMail() throws P2Exception {
- {
- //业务员邮件提醒
- // sendEmail(getMailByHrId(getString("fsaler")), getString("FAGENTSHORTNAME") + "订单已审核", getString("FAGENTSHORTNAME") + "订单已审核;订单号:" + getString("fsonum"));
- try {
- if ("NB".equals(getString("siteid"))) {
- //业务员邮件提醒
- sendReportByEmail(getMailByHrId(getString("fsaler")), "NB_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》已审核;订单号:" + getString("fsonum") + ";订单备注:" + getString("fnotes"));
- //根据领域不同发送邮件给对应的小组
- sendReportByEmail(getMailByHrGroup("NB1007", getString("fieldname")), "NB_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》已审核;订单号:" + getString("fsonum") + ";订单备注:" + getString("fnotes"));
- sendReportByEmail(getMailByHrGroup_Brand("NB1008", getString("fbrand")), "NB_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》已审核;订单号:" + getString("fsonum") + ";订单备注:" + getString("fnotes"));
- } else if ("TZ".equals(getString("siteid"))) {
- //业务员邮件提醒
- sendReportByEmail(getMailByHrId(getString("fsaler")), "TZ_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》已审核;订单号:" + getString("fsonum") + ";订单备注:" + getString("fnotes"));
- //根据领域不同发送邮件给对应的小组
- sendReportByEmail(getMailByHrGroup("TZ1007", getString("fieldname")), "TZ_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》已审核;订单号:" + getString("fsonum") + ";订单备注:" + getString("fnotes"));
- sendReportByEmail(getMailByHrGroup_Brand("TZ1008", getString("fbrand")), "TZ_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》已审核;订单号:" + getString("fsonum") + ";订单备注:" + getString("fnotes"));
- } else if ("HY".equals(getString("siteid"))) {
- //业务员邮件提醒
- sendReportByEmail(getMailByHrId(getString("fsaler")), "HY_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》已审核;订单号:" + getString("fsonum") + ";订单备注:" + getString("fnotes"));
- //根据领域不同发送邮件给对应的小组
- sendReportByEmail(getMailByHrGroup("HY1007", getString("fieldname")), "HY_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》已审核;订单号:" + getString("fsonum") + ";订单备注:" + getString("fnotes"));
- sendReportByEmail(getMailByHrGroup_Brand("TZ1008", getString("fbrand")), "HY_SAORDERDETAIL", "where=saorder.saorderid=" + getUniqueIDValue(), getString("FAGENTSHORTNAME") + "《" + getString("ftype") + "》已审核;订单号:" + getString("fsonum") + ";订单备注:" + getString("fnotes"));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- /**
- * 工具借出单审核
- *
- * @param fischeck
- * @throws P2Exception
- */
- public void check_tools(boolean fischeck) throws P2Exception {
- if (fischeck && issaleday()) {
- PaoSetRemote saorderdetailSet = getPaoSet("saorderdetail");
- int i = 0;
- while (saorderdetailSet.getPao(i) != null) {
- if ("".equals(saorderdetailSet.getPao(i).getString("fplandate"))) {
- saorderdetailSet.getPao(i).setValue("fplandate", saorderdetailSet.getPao(i).getString("fneeddate"), 11L);
- }
- i++;
- }
- }
- //订单表体,包括辅材赠品
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- double ftotalrateamount = saorderdetail.sum("frateamount");
- if (ftotalrateamount != 0) {
- taccbal taccbal = null;
- PaoSetRemote taccbalSet = getPaoSet("taccbal");
- if (taccbalSet.isEmpty()) {
- taccbal = (taccbal) taccbalSet.addAtEnd();
- taccbal.setfields(getString("fpayagentnum"), getString("faccclsnum"));
- } else {
- taccbal = (taccbal) taccbalSet.getPao(0);
- }
- Date date = getDateTime();
- ftotalrateamount = fischeck ? ftotalrateamount : -ftotalrateamount;
- PaoSetRemote ficashbillset = getPaoSet("$ficashbill_fl", "ficashbill");
- ficashbill ficashbill = (ficashbill) ficashbillset.addAtEnd();
- ficashbill.setValues("RECBILL", getString("fpayagentnum"), "收入",
- getString("faccclsnum"), date, ftotalrateamount, "工具借出申请单审核押金",
- getName(), getUniqueIDValue(), "新建", date, getUserName(), date);
- ficashbill.setValue("ftypemx", "货款", 11L);
- ficashbill.setValue("ftypemxdetail", "工具押金", 11L);
- ficashbill.check(true, taccbal);
- //Long ficashbillid = fischeck ? ficashbill.getUniqueIDValue() : 0;
- //setValue("ficashbillid", ficashbillid, 11L);
- // int i = 0;
- // while (saorderdetail.getPao(i) != null) {
- // saorderdetail.getPao(i).setValue("ficashbillid", ficashbillid, 11L);
- // i++;
- // }
- }
- if (fischeck) {
- deleteAssignment();
- /******** 单据状态更新 ********/
- setValue("fstatus", "审核", 11L);
- setValue("checkby", getUserName(), 11L);
- setValue("checkdate", getDateTime(), 11L);
- } else {
- /******** 单据状态更新 ********/
- setValue("fstatus", "提交", 11L);
- setValue("checkby", "", 11L);
- setValue("checkdate", "", 11L);
- }
- }
- /**
- * 是否年度首单计算
- *
- * @param ftotalamount
- * @return
- * @throws P2Exception
- */
- public boolean fisyearfirstorder_fl(double ftotalamount) throws P2Exception {
- if (!"标准订单".equals(getString("ftype"))) {
- return getBoolean("fisyearfirstorder_fl");
- }
- PaoRemote tagent = getPaoSet("tagents").getPao(0);
- //签约时间
- boolean fisfirstorderfl = tagent.getBoolean("fisfirstorderfl");
- if (fisfirstorderfl && ftotalamount >= tagent.getDouble("fisfirstorderflamount") && tagent.getDate("fsigningtime") != null) {
- //当前签约开始时间
- Calendar fsigningtime_beg = Calendar.getInstance();
- fsigningtime_beg.setTime(tagent.getDate("fsigningtime"));
- fsigningtime_beg.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
- //当前签约结束时间
- Calendar fsigningtime_end = Calendar.getInstance();
- fsigningtime_end.setTime(tagent.getDate("fsigningtime"));
- fsigningtime_end.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR) + 1);
- PaoSetRemote paoset = getPaoSet("$$saorder", "saorder");
- paoset.setWhere("fisyearfirstorder_fl=1 and fagentnum='" + getString("fagentnum") + "' and ftype='标准订单' and convert(varchar(10),checkdate,120)>='" + getDate_Str(fsigningtime_beg.getTime()) + "' and convert(varchar(10),checkdate,120)<'" + getDate_Str(fsigningtime_end.getTime()) + "'");
- paoset.reset();
- if (paoset.isEmpty()) {
- setValue("fisyearfirstorder_fl", true, 11L);
- setValue("fisfl", true, 11L);
- }
- }
- return getBoolean("fisyearfirstorder_fl");
- }
- /**
- * 是否年度首单计算
- *
- * @param ftotalamount
- * @return
- * @throws P2Exception
- */
- public boolean fisyearfirstorder_wl(double ftotalamount) throws P2Exception {
- if (!"标准订单".equals(getString("ftype"))) {
- return getBoolean("fisyearfirstorder_wl");
- }
- PaoRemote tagent = getPaoSet("tagents").getPao(0);
- //签约时间
- boolean fisfirstorder = tagent.getBoolean("fisfirstorder");
- if (fisfirstorder && ftotalamount >= tagent.getDouble("fisfirstorderamount")) {
- //当前签约开始时间
- Calendar fsigningtime_beg = Calendar.getInstance();
- fsigningtime_beg.setTime(tagent.getDate("fsigningtime"));
- fsigningtime_beg.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
- //当前签约结束时间
- Calendar fsigningtime_end = Calendar.getInstance();
- fsigningtime_end.setTime(tagent.getDate("fsigningtime"));
- fsigningtime_end.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR) + 1);
- PaoSetRemote paoset = getPaoSet("$$saorder", "saorder");
- paoset.setWhere("fisyearfirstorder_wl=1 and fagentnum='" + getString("fagentnum") + "' and ftype='标准订单' and convert(varchar(10),checkdate,120)>='" + getDate_Str(fsigningtime_beg.getTime()) + "' and convert(varchar(10),checkdate,120)<'" + getDate_Str(fsigningtime_end.getTime()) + "'");
- paoset.reset();
- if (paoset.isEmpty()) {
- setValue("fisyearfirstorder_wl", true, 11L);
- }
- }
- return getBoolean("fisyearfirstorder_wl");
- }
- @Override
- public int closevalidate(boolean isclose) throws P2Exception {
- //系统参数表
- PaoRemote sysVars = getSysVars();
- //是否启用发货单
- boolean fissainvoice = sysVars.getBoolean("fissainvoice");
- //订单表体
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail_view");
- Vector<PaoRemote> v = saorderdetail.getSelection();
- if (isclose) {
- if (!"审核".equals(getString("fstatus"))) {
- throw new P2AppException("", "非审核状态下不可关闭");
- }
- if (v.size() == 0) {
- throw new P2AppException("", "请勾选需要关闭的行再进行此操作");
- }
- Iterator<PaoRemote> it = v.iterator();
- while (it.hasNext()) {
- PaoRemote closepao = it.next();
- int frownum = closepao.getInt("frownum");
- if (closepao.getBoolean("fisclose")) {
- throw new P2AppException("", "行" + frownum
- + "已经关闭,不可重复关闭");
- }
- if (closepao.getDouble("fundeliqty") == 0) {
- throw new P2AppException("", "行" + frownum
- + "已发货完毕,不可关闭");
- }
- //校验是否存在未关闭的发货单
- if (fissainvoice) {
- PaoSetRemote sainvoicedetail = closepao.getPaoSet("sainvoicedetail");
- int i = 0;
- while (sainvoicedetail.getPao(i) != null) {
- PaoSetRemote sainvoice = sainvoicedetail.getPao(i)
- .getPaoSet("sainvoice");
- if (!"关闭".equals(sainvoice.getPao(0).getString("fstatus"))) {
- throw new P2AppException("", "行" + frownum
- + "存在未关闭的发货单,不可关闭");
- }
- i++;
- }
- }
- //校验是否存在新建的销售出库单
- PaoSetRemote icstockbilldetail = closepao.getPaoSet("icstockbilldetail");
- int i = 0;
- while (icstockbilldetail.getPao(i) != null) {
- PaoSetRemote icstockbill = icstockbilldetail.getPao(i)
- .getPaoSet("icstockbill");
- if ("新建".equals(icstockbill.getPao(0).getString("fstatus"))) {
- throw new P2AppException("", "行" + frownum
- + "存在新建的销售出库单,不可关闭");
- }
- i++;
- }
- }
- } else {
- if (v.size() == 0) {
- throw new P2AppException("", "请购选行再进行取消关闭操作");
- }
- Iterator<PaoRemote> it = v.iterator();
- while (it.hasNext()) {
- PaoRemote unclosepao = it.next();
- int frownum = unclosepao.getInt("frownum");
- if (!unclosepao.getBoolean("fisclose")) {
- throw new P2AppException("", "行" + frownum
- + "未关闭,不可取消关闭");
- }
- if (unclosepao.getDouble("FUNDELIQTY") == 0) {
- throw new P2AppException("", "行" + frownum
- + "已发货完毕,不可取消关闭");
- }
- }
- }
- return 1;
- }
- @Override
- public int close(boolean isclose) throws P2Exception {
- /**
- * 订单指定账户
- */
- taccbal taccbal = null;
- PaoSetRemote taccbalSet = getPaoSet("taccbal");
- if (taccbalSet.isEmpty()) {
- taccbal = (taccbal) taccbalSet.addAtEnd();
- taccbal.setfields(getString("fpayagentnum"), getString("faccclsnum"));
- } else {
- taccbal = (taccbal) taccbalSet.getPao(0);
- }
- /**
- * 订单指定账户
- */
- taccbal taccbal_fl = null;
- PaoSetRemote taccbalSet_fl = getPaoSet("taccbal_fl");
- if (taccbalSet_fl.isEmpty()) {
- taccbal_fl = (taccbal) taccbalSet_fl.addAtEnd();
- taccbal_fl.setfields(getString("fpayagentnum"), "02");
- } else {
- taccbal_fl = (taccbal) taccbalSet_fl.getPao(0);
- }
- //系统参数表
- PaoRemote sysVars = getSysVars();
- //订单账户管控是否扣款
- String fupdatebaltime = sysVars.getString("fupdatebaltime");
- //订单账户管控是否冻结金额
- String fupdatfreeztime = sysVars.getString("fupdatfreeztime");
- //订单表体
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail_view");
- // 订单指出总额
- double ftotalrateamount = saorderdetail.sum("frateamount");
- //当前时间
- Date date = getDateTime();
- // 退还金额
- double returnamount = 0;
- int i = 0;
- PaoRemote detailpao = null;
- while ((detailpao = saorderdetail.getPao(i)) != null) {
- if (detailpao.isSelected()) {
- // 订单金额
- double frateamount = detailpao.getDouble("frateamount");
- // 订单单价
- // double fprice = detailpao.getDouble("fprice");
- // 订单数量
- double fqty = detailpao.getDouble("fqty");
- // 订单未发货数量
- double fundeliqty = detailpao.getDouble("fundeliqty");
- /*计算订单关闭的退还金额*/
- //已发货数量
- double sendqty = Math.sub(fqty, fundeliqty);
- //订单单价
- double frateprice = detailpao.getDouble("frateprice");
- //已发货金额
- double sendamount = Math.mul(sendqty, frateprice, 2);
- //未发货金额
- double unsendamount = Math.sub(frateamount, sendamount);
- //退款金额
- returnamount = returnamount + unsendamount;
- if (isclose) {
- detailpao.setValue("fisclose", true, 11L);
- detailpao.setValue("fclosedate", date, 11L);
- detailpao.setValue("fclosenum", getUserName(), 11L);
- detailpao.setValue("fclosereason", getString("closereason"), 11L);
- } else {
- detailpao.setValue("fisclose", false, 11L);
- detailpao.setValue("fclosedate", "", 11L);
- detailpao.setValue("fclosenum", "", 11L);
- detailpao.setValue("fclosereason", "", 11L);
- }
- //更新促销方案商品已订购数量
- if ("促销订单".equals(getString("ftype"))) {
- PaoSetRemote tpromproducts = detailpao.getPaoSet("tpromproducts");
- if (!tpromproducts.isEmpty()) {
- PaoRemote tpromproduct = tpromproducts.getPao(0);
- if (tpromproduct.getBoolean("fislimit")) {
- //可销售数量
- double fsurplusqty = tpromproduct.getDouble("fsurplusqty");
- //更新可销售量
- tpromproduct.setValue("fsurplusqty", Math.add(fsurplusqty, fundeliqty), 11L);
- }
- }
- }
- }
- i++;
- }
- /*订单关闭账户余额更新*/
- if ("订单提交".equals(fupdatebaltime) || "订单审核".equals(fupdatebaltime)) {
- //如果是账户余额扣减
- if (isclose) {
- /*生成负数支出凭证*/
- StringBuffer fnotes = new StringBuffer();
- fnotes.append("该单由销售订单").append(getString("fsonum")).append("行关闭时自动生成;关闭原因:").append(getString("closereason"));
- //PaoSetRemote ficashbillset = getPaoSet("$ficashbill_fl", "ficashbill", "ftypemx='返利金'and fnotes not like'%行关闭%' and ftype='支出' and fstatus='审核' and fsourceobject='SAORDER' and fsourceid=" + getUniqueIDValue());
- //返利金总额
- // double fuseflamount = getDouble("fuseflamount");
- // fuseflamount = fuseflamount * (returnamount / ftotalrateamount);
- //createFicashbill_fl_Pay(taccbal_fl, -famount_fl, fnotes.toString());
- createFicashbill_Pay(taccbal, -returnamount, fnotes.toString(), true);
- } else {
- /*生成支出凭证*/
- StringBuffer fnotes = new StringBuffer();
- fnotes.append("该单由销售订单").append(getString("fsonum")).append("行反关闭时自动生成;反关闭原因:").append(getString("closereason"));
- PaoSetRemote ficashbillset = getPaoSet("$ficashbill_fl", "ficashbill", "ftypemx='返利金'and fnotes not like'%行关闭%' and ftype='支出' and fstatus='审核' and fsourceobject='SAORDER' and fsourceid=" + getUniqueIDValue());
- //返利金总额
- //double famount_fl = ficashbillset.sum("famount");
- //famount_fl = famount_fl * (returnamount / ftotalrateamount);
- //createFicashbill_fl_Pay(taccbal_fl, famount_fl, fnotes.toString());
- createFicashbill_Pay(taccbal, returnamount, fnotes.toString(), true);
- }
- } else if ("订单提交".equals(fupdatfreeztime) || "订单审核".equals(fupdatfreeztime)) {
- //如果是账户冻结金额
- //冻结列表
- PaoSetRemote taccbal_freez = getPaoSet("$TACCBAL_FREEZ",
- "taccbal_freez", "fsourceobject='" + getName()
- + "' and fsourceid='" + getUniqueIDValue() + "'");
- if (!taccbal_freez.isEmpty()) {
- PaoRemote freezPao = taccbal_freez.getPao(0);
- // 冻结金额
- double famount = freezPao.getDouble("famount");
- freezPao.setValue("famount", Math.sub(famount, returnamount), 11L);
- if (freezPao.getDouble("famount") <= 0.1) {
- taccbal_freez.deleteAll();
- }
- }
- }
- /*增加总仓可销售量 */
- //updateIcinvbal_total(isclose, true);
- //更新促销方案经销商已订购金额
- if ("促销订单".equals(getString("ftype"))) {
- PaoSetRemote tpromagents = getPaoSet("tpromagents");
- if (!tpromagents.isEmpty()) {
- PaoRemote tpromagent = tpromagents.getPao(0);
- if (tpromagent.getBoolean("fislimit") && "金额".equals(tpromagent.getString("flimittype"))) {
- //已购量
- double flimitvalue1 = tpromagent.getDouble("flimitvalue1");
- //更新已购量
- tpromagent.setValue("flimitvalue1", Math.sub(flimitvalue1, returnamount), 11L);
- }
- }
- }
- /* 注:所有行全部关闭后,表头单据状态将通过触发器自动进行更新*/
- return 1;
- }
- /**
- * 订单结案验证
- *
- * @throws P2Exception
- */
- public void closeordervalidate() throws P2Exception {
- if (!"审核".equalsIgnoreCase(getString("fstatus"))) {
- throw new P2AppException("", "非审核状态下不可进行结案操作");
- }
- if ("HY".equals(getString("siteid"))) {
- throw new P2AppException("", "当前站点不可执行订单结案操作");
- }
- DBConnect dbConnect = new DBConnect("ORACLE_TZ");
- Rows rows = dbConnect.runSqlQuery("select SO_LINE2,sum(QTY)as QTY from v_eso_shipped_qty where SO_NO2='" + getString("fsonum") + "' and ZT='" + (getString("siteid").equalsIgnoreCase("TZ") ? "IDCZJ10" : "IBPNB10") + "' group by SO_LINE2");
- if (!"".equals(rows.errmsg)) {
- throw new P2AppException("", "erp连接失败");
- }
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- saorderdetail.setOrderBy("frownum");
- saorderdetail.reset();
- for (Row row : rows) {
- int SO_LINE2 = row.getInteger("SO_LINE2");//erp订单行号
- double QTY = row.getInteger("QTY");//erp已发货数量
- int i = 0;
- while (saorderdetail.getPao(i) != null) {
- int frownum = saorderdetail.getPao(i).getInt("frownum");//订单行号
- if (SO_LINE2 == frownum) {
- saorderdetail.getPao(i).setValue("FERPDELIQTY", QTY, 11L);
- break;
- }
- i++;
- }
- }
- {
- String str = "";
- int i = 0;
- while (saorderdetail.getPao(i) != null) {
- int frownum = saorderdetail.getPao(i).getInt("frownum");//订单行号
- double fsaininvoiceqty = Math.sub(saorderdetail.getPao(i).getInt("fqty"), saorderdetail.getPao(i).getInt("fundeliqty"));//订单已发货数量
- double FERPDELIQTY = saorderdetail.getPao(i).getDouble("FERPDELIQTY");//erp已发货数量
- if (fsaininvoiceqty != FERPDELIQTY) {
- str = str + "行" + frownum + "商品发货数量" + fsaininvoiceqty + "与erp发货数量" + FERPDELIQTY + "不一致,请检查;";
- }
- i++;
- }
- if (!str.equalsIgnoreCase("")) {
- throw new P2AppException("", str);
- }
- }
- }
- /**
- * 订单结案
- *
- * @throws P2Exception
- */
- public PaoRemote closeorder() throws P2Exception {
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- int i = 0;
- while (saorderdetail.getPao(i) != null) {
- //double fundeliqty = saorderdetail.getPao(i).getInt("fundeliqty");//订单未发货数量
- double fqty = saorderdetail.getPao(i).getInt("fqty");//订单数量
- double FERPDELIQTY = saorderdetail.getPao(i).getDouble("FERPDELIQTY");//erp已发货数量
- if (fqty > FERPDELIQTY) {
- saorderdetail.getPao(i).setValue("fchangenotes", "订单结案变更", 11L);
- saorderdetail.getPao(i).setValue("fchangeqty", FERPDELIQTY, 11L);
- }
- i++;
- }
- PaoRemote pao = changesaorder(saorderdetail);
- PaoSetRemote sainvoiceSet = getPaoSet("SAINVOICE");
- int n = 0;
- while (sainvoiceSet.getPao(n) != null) {
- if (sainvoiceSet.getPao(n).getString("fstatus").equals("新建")) {
- sainvoiceSet.getPao(n).delete();
- }
- n++;
- }
- setValue("fstatus", "关闭", 11L);
- setValue("closeby", getUserName(), 11L);
- setValue("closedate", getDate(), 11L);
- setValue("CLOSEREASON", "订单结案", 11L);
- return pao;
- }
- /**
- * 一键发货生成发货单或销售出库单验证
- *
- * @throws P2Exception
- */
- public void sendoutvalidate() throws P2Exception {
- if (!"审核".equals(getString("fstatus"))) {
- throw new P2AppException("", "非审核状态下不可发货");
- }
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail_view");
- if (saorderdetail.getSelection().isEmpty()) {
- throw new P2AppException("", "请购选行再进行发货操作");
- }
- int i = 0;
- while (saorderdetail.getPao(i) != null) {
- if (saorderdetail.getPao(i).isSelected()) {
- int frownum = saorderdetail.getPao(i).getInt("frownum");
- if (saorderdetail.getPao(i).getBoolean("fisclose")) {
- throw new P2AppException("", "行" + frownum + "已经关闭,不可发货");
- }
- if (saorderdetail.getPao(i).getDouble("fundeliqty") == 0) {
- throw new P2AppException("", "行" + frownum + "已发货完毕,不可发货");
- }
- }
- i++;
- }
- }
- /**
- * 一键发货生成发货单或销售出库单
- *
- * @throws P2Exception
- */
- public PaoRemote sendout(String foutplace) throws P2Exception {
- //系统参数表
- PaoRemote sysVars = getSysVars();
- //是否发货单管理。如果为true,则发货时生成发货单。否则直接生成销售出库单
- boolean fissainvoice = sysVars.getBoolean("fissainvoice");
- PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view");
- if (fissainvoice) {
- // 生成发货单
- PaoSetRemote sainvoiceset = getPaoSet("sainvoice");
- sainvoiceset.setApp("SAINVOICE");
- sainvoice sainvoice = (sainvoice) sainvoiceset.addAtEnd();
- sainvoice.setValue("fsonum", getString("fsonum"));
- sainvoice.additemnos(saorderdetail_view);
- return sainvoice;
- } else {
- // 生成销售出库单
- PaoSetRemote icstockbillset = getPaoSet("icstockbill");
- icstockbillset.setWhere("fstatus='新建'");
- icstockbillset.reset();
- icstockbillset.setApp("STOCKBILL0");
- icstockbill icstockbill = null;
- if (icstockbillset.isEmpty()) {
- icstockbill = (icstockbill) icstockbillset.addAtEnd();
- icstockbill.setValue("fsourceid", getUniqueIDValue());
- icstockbill.setValue("fsourceobject", getName());
- icstockbill.setValue("fagentnum", getString("fagentnum"));
- icstockbill.setValue("fnotes", getString("fnotes"));
- icstockbill.setValue("foutplace", foutplace, 11L);
- icstockbill.setValue("faddress", getString("faddress"));
- icstockbill.setValue("fcontact", getString("fcontact"));
- icstockbill.setValue("fphonenumber", getString("fphonenumber"));
- icstockbill.setValue("finvoicename", getString("finvoicename"), 11L);
- icstockbill.setValue("finvoiceaddress", getString("finvoiceaddress"), 11L);
- icstockbill.setValue("finvoicetaxnumber", getString("finvoicetaxnumber"), 11L);
- } else {
- icstockbill = (icstockbill) icstockbillset.getPao(0);
- PaoSetRemote icstockbilldetail = icstockbill.getPaoSet("icstockbilldetail");
- int i = 0;
- while (saorderdetail_view.getPao(i) != null) {
- if (saorderdetail_view.getPao(i).isSelected()) {
- long saorderdetailid = saorderdetail_view.getPao(i)
- .getUniqueIDValue();
- int m = 0;
- while (icstockbilldetail.getPao(m) != null) {
- if (icstockbilldetail.getPao(m).getLong(
- "saorderdetailid") == saorderdetailid) {
- icstockbilldetail.getPao(m).setValue(
- "fqty",
- saorderdetail_view.getPao(i).getDouble(
- "fqty"));
- saorderdetail_view.getPao(i).unselect();
- break;
- }
- m++;
- }
- }
- i++;
- }
- }
- icstockbill.addRowsFromSaorder(saorderdetail_view);
- icstockbill.setValue("fpayamount", icstockbill.getPaoSet("icstockbilldetail_view").sum(
- "ftaxamount"), 11L);
- return icstockbill;
- }
- }
- /**
- * 配送方案生成
- *
- * @return
- * @throws P2Exception
- */
- public void createrationvalidate() throws P2Exception {
- if (!"新建".equals(getString("fstatus"))) {
- throw new P2AppException("", "非新建状态下不可生成配送方案");
- }
- if (!getPaoSet("saorderdetail_view2").isEmpty()) {
- throw new P2AppException("", "已生成配送方案,不可重复生成");
- }
- }
- /**
- * 配送方案生成
- *
- * @return
- * @throws P2Exception
- */
- public void createration() throws P2Exception {
- PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view");
- ArrayList<HashMap<String, Object>> list = runQuerySQL("exec [SAORDEROPENRATION]'"
- + getUniqueIDValue() + "'");
- for (HashMap<String, Object> map : list) {
- String fitemno = map.get("fitemno") + "";
- double fqty = new Double(map.get("fqty") + "");
- double frationqty = new Double(map.get("frationqty") + "");
- double fprice = new Double(map.get("fprice") + "");
- double frationminqty = new Double(map.get("frationminqty") + "");
- double frationismincaculate = new Double(map.get("frationismincaculate") + "");
- long saorderdetailid = new Long(map.get("saorderdetailid") + "");
- String frationnum = map.get("frationnum") + "";
- String frationtype = map.get("frationtype") + "";
- PaoRemote pao = saorderdetail_view.addAtEnd();
- pao.setValue("fisration", true, 2L);
- pao.setValue("fitemno", fitemno, 2L);
- pao.setValue("fqty", fqty, 2L);
- pao.setValue("fprice", fprice, 2L);
- pao.setValue("frationnum", frationnum, 11L);
- pao.setValue("frationtype", frationtype, 11L);
- pao.setValue("fsaorderdetailid", saorderdetailid, 11L);
- pao.setValue("frationqty", frationqty, 11L);
- pao.setValue("frationminqty", frationminqty, 11L);
- pao.setValue("frationismincaculate", frationismincaculate, 11L);
- }
- if (!list.isEmpty()) {
- setValue("fisration", true, 11L);
- }
- }
- /**
- * 清空辅材方案验证
- *
- * @throws P2Exception
- */
- public void deleterationvalidate() throws P2Exception {
- if (!"新建".equals(getString("fstatus"))) {
- throw new P2AppException("", "非新建状态下不可清空配送方案");
- }
- }
- /**
- * 清空辅材方案
- *
- * @throws P2Exception
- */
- public void deleteration() throws P2Exception {
- getPaoSet("saorderdetail_view2").deleteAll();
- setValue("fisration", false, 11L);
- }
- @Override
- public void fieldAction(Object paoField, String fieldname)
- throws P2Exception {
- super.fieldAction(paoField, fieldname);
- if ("FAGENTNUM".equals(fieldname)) {
- setValue("fpayagentnum", getString("fagentnum"), 11L);
- setValue("frecagentnum", getString("fagentnum"), 11L);
- PaoSetRemote tagents = getPaoSet("tagents");
- if (!"".equals(getString("fagentnum")) && !tagents.isEmpty()) {
- if (!"促销订单".equals(getString("ftype")) && !"工具借出单".equals(getString("ftype"))) {
- setValue("faccclsnum", "01");
- }
- PaoRemote agentpao = tagents.getPao(0);
- // // 设置业务员
- // PaoSetRemote tsalearea = agentpao.getPaoSet(
- // "tsalearea");
- // if (!tsalearea.isEmpty()) {
- // setValue("fsaler", tsalearea.getPao(0).getString("fsaler"));
- // } else {
- // setValue("fsaler", "");
- // }
- // 默认收货地址设置
- PaoSetRemote tagents_address = agentpao.getPaoSet(
- "tagents_address_default");
- if (!tagents_address.isEmpty()) {
- PaoRemote address = tagents_address.getPao(0);
- setValue("fcontact", address.getString("fcontact"));
- setValue("fphonenumber", address.getString("fphonenumber"));
- setValue("faddress", address.getString("faddress"));
- setValue("fprovince", address.getString("fprovince"), 11L);
- setValue("fcity", address.getString("fcity"), 11L);
- setValue("fcounty", address.getString("fcounty"), 11L);
- }
- // 默认开票信息设置
- PaoSetRemote tagents_invoice = agentpao.getPaoSet("tagents_invoice_default");
- if (!tagents_invoice.isEmpty()) {
- PaoRemote invoice = tagents_invoice.getPao(0);
- setValue("finvoicename", invoice.getString("fname"), 11L);
- setValue("finvoicetaxnumber", invoice.getString("ftaxnumber"), 11L);
- setValue("finvoiceaddress", invoice.getString("faddress"), 11L);
- }
- PaoSetRemote tagents_field = agentpao.getPaoSet("tagents_field");
- if (!tagents_field.isEmpty()) {
- setValue("fieldname", tagents_field.getPao(0).getString("fieldname"), 11L);
- setValue("fsaler", tagents_field.getPao(0).getString("hrid"), 11L);
- }
- PaoSetRemote tagents_brand = agentpao.getPaoSet("tagents_brand");
- if (!tagents_brand.isEmpty()) {
- setValue("fbrand", tagents_brand.getPao(0).getString("fbrand"), 11L);
- }
- } else {
- setValue("faccclsnum", "");
- setValue("fsaler", "");
- setValue("fcontact", "", 11L);
- setValue("fphonenumber", "", 11L);
- setValue("faddress", "", 11L);
- setValue("finvoicename", "", 11L);
- setValue("finvoicetaxnumber", "", 11L);
- setValue("finvoiceaddress", "", 11L);
- setValue("fprovince", "", 11L);
- setValue("fcity", "", 11L);
- setValue("fcounty", "", 11L);
- }
- } else if ("FPROMNUM".equals(fieldname)) {
- if ("促销订单".equals(getString("ftype"))) {
- if ("打包促销".equals(getString("tpromotions.ftype"))) {
- setFieldFlag("fpromqty", READONLY, false);
- setFieldFlag("fpromqty", REQUIRED, true);
- } else {
- setFieldFlag("fpromqty", READONLY, true);
- setFieldFlag("fpromqty", REQUIRED, false);
- }
- }
- } else if ("FPROMQTY".equals(fieldname)) {
- double fpromqty = getDouble("fpromqty");
- if (fpromqty == 0) {
- getPaoSet("saorderdetail_view").deleteAll();
- getPaoSet("saorderdetail_view").deleteAndRemoveAll();
- setFieldFlag("fpromnum", READONLY, false);
- } else {
- PaoSetRemote tpromproducts = getPaoSet("tpromproducts");
- int i = 0;
- PaoRemote pao = null;
- while ((pao = tpromproducts.getPao(i)) != null) {
- //打包数量
- double fpackingqty = pao.getDouble("fpackingqty");
- pao.setValue("faddqty", fpromqty * fpackingqty);
- pao.select();
- i++;
- }
- additems_prom(tpromproducts);
- setFieldFlag("fpromnum", READONLY, true);
- }
- } else if ("FACCCLSNUM".equals(fieldname)) {
- if ("02".equals(getString(fieldname))) {
- setValue("fisusefl", false, 11L);
- setFieldFlag("fisusefl", READONLY, true);
- } else {
- setFieldFlag("fisusefl", READONLY, false);
- }
- } else if ("FISUSEFL".equals(fieldname)) {
- //double ftotalamount = getPaoSet("saorderdetail_view").sum("famount");
- //double fmjamount = caculateMJ();
- //caculateUseFLAmount(Math.sub(ftotalamount, fmjamount));
- } else if ("FTYPE".equals(fieldname)) {
- if ("特殊订单".equals(getString(fieldname))) {
- setFieldFlag("ftypemx", READONLY, false);
- } else {
- setValue("ftypemx", "普通", 11L);
- setFieldFlag("ftypemx", READONLY, true);
- }
- } else if ("FPLANDATE".equals(fieldname)) {
- //回复交期
- PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view");
- int i = 0;
- while (saorderdetail_view.getPao(i) != null) {
- if (saorderdetail_view.getPao(i).getPaoSet("titem").getPao(0).getBoolean("fissaleday")) {
- saorderdetail_view.getPao(i).setValue("fplandate", getDate(fieldname), 11L);
- }
- i++;
- }
- } else if ("FNEEDDATE".equals(fieldname)) {
- //回复交期
- PaoSetRemote saorderdetail_view = getPaoSet("saorderdetail_view");
- int i = 0;
- while (saorderdetail_view.getPao(i) != null) {
- if (saorderdetail_view.getPao(i).getPaoSet("titem").getPao(0).getBoolean("fissaleday")) {
- saorderdetail_view.getPao(i).setValue("fneeddate", getDate(fieldname), 11L);
- }
- i++;
- }
- }
- }
- @Override
- public void fieldValidate(Object paoField, String fieldname) throws P2Exception {
- super.fieldValidate(paoField, fieldname);
- if ("FPROMQTY".equals(fieldname)) {
- double fpromqty = getDouble("fpromqty");
- if (fpromqty < 0) {
- throw new P2AppException("", "数量不可小于0");
- }
- } else if ("FPROJECTNOTES".equals(fieldname)) {
- PaoSetRemote tprojectSet = getPaoSet("$tproject", "tproject");
- tprojectSet.setWhere("fstatus='审核' and fieldname='" + getString("fieldname") + "' and fprojectname like'%" + getString("fprojectnotes") + "%' and ((fbegdate<=tproject.fbegdate and fenddate>=tproject.fbegdate ) or (fbegdate<=tproject.fenddate and fenddate>=tproject.fenddate ))");
- tprojectSet.reset();
- if (!tprojectSet.isEmpty()) {
- ((PaoSet) getThisPaoSet()).addWarning(new P2AppException("", "当前项目有效期内已存在审核的项目报备"));
- }
- }
- }
- @Override
- public PaoSetRemote fieldGetlist(Object paoField, PaoSetRemote list, String fieldname) throws P2Exception {
- if ("FPAYAGENTNUM".equals(fieldname)) {
- PaoSetRemote tagentsSet = getPaoSet("tagents");
- if (!tagentsSet.isEmpty()) {
- SQLFactory factory = new SQLFactory(this, "结算客户查询");
- factory.addParameter("siteid", getInsertSite());
- factory.addParameter("fagentnum", getString("fagentnum"));
- DBConnect dbConnect = new DBConnect();
- Rows rows = dbConnect.runSqlQuery(factory.getSQL());
- String where = rows.getInWhere("fagentnum");
- list.setWhere("fagentnum in " + where);
- } else {
- list.setWhere("1=2");
- }
- }
- return super.fieldGetlist(paoField, list, fieldname);
- }
- public void getStockStatus() throws P2Exception {
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- String[] fitemnos = getDistinctString(saorderdetail, "fitemno", false);
- String where = "";
- for (String fitemno : fitemnos) {
- if ("".equals(where)) {
- where = "'" + fitemno + "'";
- } else {
- where = where + ",'" + fitemno + "'";
- }
- }
- if (!"".equals(where)) {
- PaoSetRemote titemSet = getPaoSet("$titem", "titem", "fitemno in (" + where + ")");
- int i = 0;
- titem titem = null;
- while ((titem = (titem) titemSet.getPao(i)) != null) {
- titem.initStockMsg();
- i++;
- }
- }
- }
- /**
- * 是否缺货检查
- *
- * @throws P2Exception
- */
- public boolean checkStockStatus() throws P2Exception {
- getStockStatus();
- PaoSetRemote saorderdetail = getPaoSet("saorderdetail");
- int i = 0;
- while (saorderdetail.getPao(i) != null) {
- if (saorderdetail.getPao(i).getDouble("fqty") > saorderdetail.getPao(i).getPaoSet("titem").getPao(0).getDouble("ficqty")) {
- return false;
- }
- i++;
- }
- return true;
- }
- public void changesaorder_validate(PaoSetRemote paoSetRemote) throws P2Exception {
- int i = 0;
- PaoRemote orderdetail = null;
- while ((orderdetail = paoSetRemote.getPao(i)) != null) {
- double fqty = orderdetail.getDouble("fqty");
- double fchangeqty = orderdetail.getDouble("fchangeqty");
- String fchangenotes = orderdetail.getString("fchangenotes");
- if (fqty != fchangeqty && !orderdetail.getString("fchangeqty").equals("")) {
- if (fchangenotes.equals("")) {
- throw new P2AppException("", "修改备注不可为空");
- }
- }
- i++;
- }
- }
- public PaoRemote changesaorder(PaoSetRemote paoSetRemote) throws P2Exception {
- changesaorder_validate(paoSetRemote);
- HashMap<Long, saorderdetail> saorderdetailmap = new HashMap<>();
- HashMap<Long, Double> saorderdetailchangeamount = new HashMap<>();
- PaoSetRemote saorderdetail_changeSet = getPaoSet("$saorderdetail_change", "saorderdetail_change");
- HashMap<Long, Double> map = new HashMap<Long, Double>();
- int i = 0;
- long id = 0;
- PaoRemote saorderdetail_changePao = null;
- PaoRemote orderdetail = null;
- while ((orderdetail = paoSetRemote.getPao(i)) != null) {
- double fqty = orderdetail.getDouble("fqty");
- double fchangeqty = orderdetail.getDouble("fchangeqty");
- String fchangenotes = orderdetail.getString("fchangenotes");
- Long saorderdetailid = orderdetail.getUniqueIDValue();
- if (fqty != fchangeqty && !orderdetail.getString("fchangeqty").equals("")) {
- PaoRemote saorderdetail_change = saorderdetail_changeSet.addAtEnd();
- if (id == 0) {
- id = saorderdetail_change.getUniqueIDValue();
- saorderdetail_changePao = saorderdetail_change;
- }
- saorderdetail_change.setValue("id", id);
- saorderdetail_change.setValue("foldqty", fqty);
- saorderdetail_change.setValue("fqty", fchangeqty);
- saorderdetail_change.setValue("fchangenotes", fchangenotes);
- saorderdetail_change.setValue("saorderdetailid", saorderdetailid);
- saorderdetail_change.setValue("saorderid", getUniqueIDValue());
- saorderdetail_change.setValue("createby", getUserName());
- saorderdetail_change.setValue("createdate", getDate());
- map.put(saorderdetailid, fchangeqty);
- }
- i++;
- }
- PaoSetRemote saorderdetailSet = getPaoSet("saorderdetail");
- double foldrateamount = saorderdetailSet.sum("frateamount");
- int n = 0;
- while (saorderdetailSet.getPao(n) != null) {
- long detailid = saorderdetailSet.getPao(n).getUniqueIDValue();
- if (map.containsKey(detailid)) {
- double fprice = saorderdetailSet.getPao(n).getDouble("fprice");
- //double fmjamount = saorderdetailSet.getPao(n).getDouble("fmjamount");//行满减金额
- //double fflamount = saorderdetailSet.getPao(n).getDouble("fflamount");//行返利金额
- double fnewqty = map.get(detailid);
- double foldqty = saorderdetailSet.getPao(n).getDouble("fqty");
- double foldundeliqty = saorderdetailSet.getPao(n).getDouble("fundeliqty");
- double faddqty = fnewqty - foldqty;//新增的数量
- saorderdetailSet.getPao(n).setValue("fqty", foldqty + faddqty, 11L);
- saorderdetailSet.getPao(n).setValue("fundeliqty", foldundeliqty + faddqty, 11L);
- saorderdetailSet.getPao(n).setValue("famount", map.get(detailid) * fprice, 11L);
- double famount = saorderdetailSet.getPao(n).getDouble("famount");
- //saorderdetailSet.getPao(n).setValue("frateamount", Math.add(famount, Math.add(-fmjamount, -fflamount)), 11L);
- //saorderdetailSet.getPao(n).setValue("frateprice", saorderdetailSet.getPao(n).getDouble("frateamount") / saorderdetailSet.getPao(n).getDouble("fqty"), 11L);
- saorderdetailSet.getPao(n).setValue("frateamount", fnewqty * saorderdetailSet.getPao(n).getDouble("frateprice"), 11L);
- /**
- * 核销对冲计算
- */
- double fwriteoffamount = saorderdetailSet.getPao(n).getDouble("fwriteoffamount");//已核销金额
- if (fwriteoffamount > 0 && saorderdetailSet.getPao(n).getDouble("frateamount") < fwriteoffamount) {
- //如果已核销金额大于0 且调整后折后金额小于已核销金额,则需要将差价进行回冲
- saorderdetailmap.put(detailid, (saorderdetail) saorderdetailSet.getPao(n));
- saorderdetailchangeamount.put(detailid, Math.sub(fwriteoffamount, saorderdetailSet.getPao(n).getDouble("frateamount")));
- }
- }
- n++;
- }
- double fnewrateamount = saorderdetailSet.sum("frateamount");
- double ce = Math.sub(fnewrateamount, foldrateamount);
- if (ce != 0) {
- /**
- * 订单指定账户
- */
- taccbal taccbal = null;
- PaoSetRemote taccbalSet = getPaoSet("taccbal");
- if (taccbalSet.isEmpty()) {
- taccbal = (taccbal) taccbalSet.addAtEnd();
- taccbal.setfields(getString("fpayagentnum"), getString("faccclsnum"));
- } else {
- taccbal = (taccbal) taccbalSet.getPao(0);
- }
- createFicashbill_Pay(taccbal, ce, "订单调整" + getString("fsonum"), true);
- // if (saorderdetail_changePao != null) {?//
- // boolean issuccess = new UploadDataToERP(saorderdetail_changePao, getUserInfo()).upload();?//
- // }
- }
- /**
- * 核销对冲
- */
- if (!saorderdetailmap.isEmpty()) {
- new twriteoffbill_orderchange(this, saorderdetailmap, saorderdetailchangeamount).hedging();
- }
- return saorderdetail_changePao;
- }
- @Override
- public PaoRemote duplicate() throws P2Exception {
- PaoRemote pao = super.duplicate();
- try {
- pao.setValue("createflag", getThisPaoSet().getApp().contains("管理"), 11L);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return pao;
- }
- }
|