# app_script_history

id: 663aec3e9932a08a57e3ef43
scriptid: 66382c259932a08a57e3e707
tablename: app_script
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 11:06:39.000
script:
/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {
    update_pzs(gguid);

}

function update_pzs(gguid) {
    runSQL("", ` update pzb set pzs= (select count(*) from pzbmx where pzbmx.gguid='${gguid}' ) where  gguid= '${gguid}' `, true);
}

function back_buildRange(pzh1, pzh2) {

    var pzh = [];
    var c = 0;

    var t = pzh1;
    while (t <= pzh2) {
        pzh.push(t);
        c++;
        if (c > 3000) return { success: false, message: '一次添加凭证号不能大于3000笔' }
        t = stringInc(t);

    }
    return { success: true, pzh: pzh };
}


function back_add_pzh(gguid, corpid, ym, pzhs) {
    var ds = newDataStore('', 'select * from pzbmx');
    ds.setUpdateProperty('pzbmx', 'id', '*', 'id');
    // create unique index  ui_pzbmx_pzh on  pzbmx ( corpid, ym ,pzh)
    var c = 0;
    for (var i = 0; i < pzhs.length; i++) {
        ds.reset();
        var row = ds.insertRow(0);
        var pzh = pzhs[i];
        ds.setValue(row, "id", corpid + '-' + ym + '-' + pzh);
        ds.setValue(row, "gguid", gguid);
        ds.setValue(row, "corpid", corpid);
        ds.setValue(row, "ym", ym);
        ds.setValue(row, "pzh", pzh);
        ds.setValue(row, "createdate", newDate());

        if (ds.update(true)) {
            c++; //如果存在，更新会失败，也没关系
        } else {
            println(ds.getErrorMessage());
        }

    }

    update_pzs(gguid);

    return { message: '本次成功添加 ' + c + ' 个凭证号' };

}




function back_delete_pzh(gguid, pzh1, pzh2) {
    var c = getIntFromSQL(`select count(*) as c  from pzbmx where gguid='${gguid}'   and pzh>='${pzh1}' and pzh<='${pzh2}'  `);
    runSQL('', `delete from pzbmx where gguid='${gguid}'   and pzh>='${pzh1}' and pzh<='${pzh2}'  `)
    update_pzs(gguid);
    return { message: '本次成功删除 ' + c + ' 个凭证号' };

}


id: 663aec3e9932a08a57e3ef47
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 11:07:25.000
script:
function cb_auto_pzh_onClick() {
    showInfoPane("* 正在自动构造凭证清册");
    setTimeout(function () {
        runTask("autoRebuildPZB", { corpid: $pzbmx_ds.getString(0, "corpid"), ym: $pzb_ds.getString(0, "ym") }, function () {
            hideInfoPane();
            toastr.info("构建完成");
            reloadData();
        });
    }, 500);
}


function cb_add_pzh_onClick() {

    book.sheet1.cells("pzh1").setValue(null);
    book.sheet1.cells("pzh2").setValue(null);

    book.sheet1.popup('fa fa-cog', '输入凭证号范围', 300, 105, true, true,
        {
            action1:
            {
                text: '确定',

                action: function () {
                    let pzh1 = book.sheet1.cells("pzh1").getValueString();
                    let pzh2 = book.sheet1.cells("pzh2").getValueString();
                    let range = buildRange(pzh1, pzh2);
                    if (!range.success) {
                        toastr.error(range.message);
                        return null;
                    }

                    showInfoPane('*正在添加凭证号');

                    setTimeout(function () {
                        back_add_pzh(
                            $pzb_ds.getString(0, "gguid"),
                            $pzb_ds.getString(0, "corpid"),
                            $pzb_ds.getString(0, "ym"),
                            range.pzh, function (ret) {
                                hideInfoPane();
                                toastr.info(ret.message);
                                reloadData();

                            });
                    }, 600);
                    return true;
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

                    return true; //表示不关闭弹窗
                }
            }

        });

}




function cb_delete_pzh_onClick() {

    book.sheet1.cells("pzh1").setValue(null);
    book.sheet1.cells("pzh2").setValue(null);

    book.sheet1.popup('fa fa-cog', '输入凭证号范围', 300, 105, true, true,
        {
            action1:
            {
                text: '确定',

                action: function () {
                    let pzh1 = book.sheet1.cells("pzh1").getValueString();
                    let pzh2 = book.sheet1.cells("pzh2").getValueString();
                    let range = buildRangeForDelete(pzh1, pzh2);
                    if (!range.success) {
                        toastr.error(range.message);
                        return null;
                    }

                    showInfoPane('*正在删除凭证号');

                    setTimeout(function () {
                        back_delete_pzh(
                            $pzb_ds.getString(0, "gguid"),
                            range.pzh1,
                            range.pzh2,
                            function (ret) {
                                hideInfoPane();
                                toastr.info(ret.message);
                                reloadData();

                            });
                    }, 600);
                    return true;
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

                    return true; //表示不关闭弹窗
                }
            }

        });

}



function reloadData() {
    smartRetrieve(book.sheet0, 'pzb');
    smartRetrieve(book.sheet0, 'pzbmx');
}

function buildRange(pzh1, pzh2) {
    if (pzh1 == '' && pzh2 == '') return { success: false, message: '请至少输入一个凭证号', pzh: [] };
    if (pzh1 != '' && pzh2 == '') return { success: true, pzh: [pzh1] };
    if (pzh2 != '' && pzh1 == '') return { success: true, pzh: [pzh2] };

    if (pzh1.length != pzh2.length) return { success: false, message: '起始凭证号与终止凭证号长度必须一样', pzh: [] };
    if (pzh1 > pzh2) return { success: false, message: '起始凭证号必须大于等于终止凭证号', pzh: [] };

    let c = 0;
    let ret = back_buildRange( pzh1,pzh2); 
    return ret; 

}



function buildRangeForDelete(pzh1, pzh2) {
    if (pzh1 == '' && pzh2 == '') return { success: false, message: '请至少输入一个凭证号' };
    if (pzh1 != '' && pzh2 == '') return { success: true, pzh1: pzh1, pzh2: pzh1 };
    if (pzh2 != '' && pzh1 == '') return { success: true, pzh1: pzh2, pzh2: pzh2 };

    if (pzh1.length != pzh2.length) return { success: false, message: '起始凭证号与终止凭证号长度必须一样' };
    if (pzh1 > pzh2) return { success: false, message: '起始凭证号必须大于等于终止凭证号' };

    return { success: true, pzh1: pzh1, pzh2: pzh2 };


}


id: 663aec3e9932a08a57e3ef52
scriptid: 66382c259932a08a57e3e707
tablename: app_script
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 11:08:14.000
script:
/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {
    update_pzs(gguid);

}

function update_pzs(gguid) {
    runSQL("", ` update pzb set pzs= (select count(*) from pzbmx where pzbmx.gguid='${gguid}' ) where  gguid= '${gguid}' `, true);
}

function back_buildRange(pzh1, pzh2) {

    var pzh = [];
    var c = 0;

    var t = pzh1;
    while (t <= pzh2) {
        pzh.push(t);
        c++;
        if (c > 3000) return { success: false, message: '一次添加凭证号不能大于3000笔' }
        t = stringInc(t);

    }
    return { success: true, pzh: pzh };
}


function back_add_pzh(gguid, corpid, ym, pzhs) {
    var ds = newDataStore('', 'select * from pzbmx');
    ds.setUpdateProperty('pzbmx', 'id', '*', 'id');
    // create unique index  ui_pzbmx_pzh on  pzbmx ( corpid, ym ,pzh)
    var c = 0;
    for (var i = 0; i < pzhs.length; i++) {
        ds.reset();
        var row = ds.insertRow(0);
        var pzh = pzhs[i];
        ds.setValue(row, "id", corpid + '-' + ym + '-' + pzh);
        ds.setValue(row, "gguid", gguid);
        ds.setValue(row, "corpid", corpid);
        ds.setValue(row, "ym", ym);
        ds.setValue(row, "pzh", pzh);
        ds.setValue(row, "createdate", newDate());

        if (ds.update(true)) {
            c++; //如果存在，更新会失败，也没关系
        } else {
            println(ds.getErrorMessage());
        }

    }

    update_pzs(gguid);

    return { message: '本次成功添加 ' + c + ' 个凭证号' };

}




function back_delete_pzh(gguid, pzh1, pzh2) {
    var c = getIntFromSQL(`select count(*) as c  from pzbmx where gguid='${gguid}'   and pzh>='${pzh1}' and pzh<='${pzh2}'  `);
    runSQL('', `delete from pzbmx where gguid='${gguid}'   and pzh>='${pzh1}' and pzh<='${pzh2}'  ` ,true)
    update_pzs(gguid);
    return { message: '本次成功删除 ' + c + ' 个凭证号' };

}


id: 663b18b199327b97e92d770b
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 14:28:22.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd ( flow , node , gguid  ) {
    // println( flow.id) ; //流程定义的ID
    println( gguid+"工作结束了");

    runSQL("",  `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = a.towhere , a.memo = c.summary    ` , true); 
}


id: 663b1be899327b97e92d7716
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 14:32:00.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd ( flow , node , gguid  ) {
    // println( flow.id) ; //流程定义的ID
    println( gguid+"工作结束了");

    runSQL("",  `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true); 
}


id: 663c5d6c9932dd09009e9573
scriptid: 618b531c9932fda9010e7047
tablename: app_script
clientip: 36.27.100.6
username: sa
createdate: 2024.05.10 16:34:27.000
script:
function main() {
    runSQL('', " create index di_dzpz_pzfj_gguid_groupname_info1 on dzpz_pzfj ( gguid, groupname, info1) ", "");
    runSQL('', " create index di_dzpz_pz_corpid_ym_pzh on dzpz_pz  ( corpid, ym,pzh  )", true);

    runSQL("", "SET GLOBAL  tmp_table_size =1024*1024*1024 ", true);

    runSQL("", "SET GLOBAL innodb_buffer_pool_size=67108864 ", true);

}


id: 663ddc279932dd09009e957f
scriptid: 60d0840b0c749ebb22855746
tablename: app_script
clientip: 36.27.100.6
username: sa
createdate: 2024.05.10 16:35:32.000
script:
function main(arg) {
    println(arg );
    var p = JSON.parse(arg);
    var id = p.id;
    var overwrite = p.overwrite;

    // info2 是手工调整顺序后的序号 ，如果没有手工调整顺序，那么info2应该都是null , 
    // 这样，如果手工调整了顺序，那么以手工调整后的顺序来排序，
    //否则以(groupname优先排序，它通常是“凭证”，“附件”) 凭证排在前，附件排在后 ，同类型（groupname）文件的按原始日期来排序，

    var tds = newDataStore("", "select pzh , corpid from dzpz_pz where id='" + id + "'");
    tds.retrieve();
    var pzh = tds.getString(0, "pzh");
    var corpid = tds.getString(0, "corpid");
    println("pzh="+ pzh);
    println("corpid="+ corpid);

    var url = getStringFromSQL("select url_img  from basic_corp_seal a , basic_corp b where a.gguid=b.gguid and a.groupname='电子印章' and b.code= '" + corpid + "' ");
    println( url);

    if( getIntFromSQL("select count(*) from dzpz_pzfj where gguid='"+id+"' ")==0)
    {
        return {sccess:false, message: "凭证归档信息丢失,禁止重新生成pdf "};
         
    }

    //把附件打包成一个PDF ,生成pdf不要加水印，水印是在下载时临时加上去的
    return createArchive("dzpz", 
         id,
        "info2 asc , groupname , info1 asc ",  //附件排序规则
        overwrite, //是否强行重新生成
        '', //水印 。生成pdf不要加水印，水印是在下载时临时加上去的
        {
            left: 20,
            top: 20,
            url:  url
        },  //左上角加一个印章图片
        pzh //右上角把凭证号打上，便于查看
    );


}


id: 663ddc279932dd09009e9586
scriptid: 60a31c3c5db27838e0c012a2
tablename: app_template
clientip: 36.27.100.6
username: sa
createdate: 2024.05.10 16:36:47.000
script:
var labelDataInited = false;

/**
 * 表单初始化完成后，执行此事件
 */
//@comment (group=表单事件,caption=表单初始化完成)
function formOpen() {
    book.showTabOnWhere = "top";
    $dzpz_pzbq_ds.reset();
    var s = $dzpz_pz_ds.getString(0, "labeldata");
    if (s == '') s = "{}";
    var data = JSON.parse(s);
    if (typeof (data) != 'object') data = {};
    for (var name in data) {
        var value = data[name];
        if (['凭证号', '记帐期'].contains(name)) continue;
        var row = $dzpz_pzbq_ds.insertRow(999);
        $dzpz_pzbq_ds.setValue(row, { name: name, value: value });
    }
    labelDataInited = true;


}

//图片控件初始化之前的处理，注入参数
function imageGridlyBeforeInit(sheet, name, data) {
    sheet.getBrick(name).config.uploadButtonDisabled = true;
    sheet.getBrick(name).config.deleteButtonDisabled = true;
}

/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    if (dsname == 'dzpz_pzbq') {
        rebuildLabel();
    }
}


function rebuildLabel() {
    if (!labelDataInited) return;
    var label = { '凭证号': $dzpz_pz_ds.getString(0, "pzh"), '记帐期': $dzpz_pz_ds.getInt(0, "ym") };
    for (var i = 0; i < $dzpz_pzbq_ds.rowCount; i++) {
        var name = $dzpz_pzbq_ds.getString(i, "name");

        var value = $dzpz_pzbq_ds.getString(i, "value");
        if (name == '') continue;
        label[name] = value;
    }

    $dzpz_pz_ds.setValue(0, "labeldata", JSON.stringify(label));

}


function cb_download_onClick() {
    packageGo('download');
}


function cb_view_onClick() {
    var url = $app_archive_ds.getString(0, "url_img");
    if (url != '') {
        openWindow(url);
    } else {
        packageGo('view');
    }
 
}

function packageGo(action) {
    var ret = JSON.parse(runTask("pz_image2pdf", {
        id: currentGUID(),
        overwrite: false  //如果已存在，不要重新生成
    }));
    console.dir(ret);
    if (ret.success) {
        smartRetrieve(book.sheet0, "app_archive");
        let url = ret.data.url_img;
        if (action == 'download') url = url.replace('action=view', 'action=download');
        url = safeURL(safeURL(url)); //没有其它意思，就是测试一下safeURL的幂等性
        console.info(url);
        openWindow(url);
    } else {
        $.alert(ret.message);
    }
}


id: 665350b299327550ff10da97
scriptid: 66534a9199327550ff10da2c
tablename: app_script
clientip: 60.177.72.27
username: sa
createdate: 2024.05.26 23:25:57.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
     

     println( arg);
    var p= JSON.parse(arg);
   
    var id= p.pzid;
     

    var  dzpz_pz_ds = newDataStore("", "select * from dzpz_pz ");  //凭证主记录
    dzpz_pz_ds.retrieve(" id='"+  id+"' ");

    var  dzpz_pzfj_ds = newDataStore("", "select * from dzpz_pzfj "); //凭证附件
    var n = dzpz_pzfj_ds.retrieve(" gguid='"+  id+"' "); 
    
 
    var corpid= dzpz_pz_ds.getValue(0,"corpid");
    var ym  = dzpz_pz_ds.getString(0,"ym");
    var pzh  = dzpz_pz_ds.getString(0,"pzh");

    var data={};
    data.dzpz_pz = dzpz_pz_ds.getJSONRow( 0, true);
    data.dzpz_pzfj =[];
    for( var i=0;i< n;  i++)
    {
        data.dzpz_pzfj.push( JSON.parse( dzpz_pzfj_ds.getJSOnRow(i,true) ));
    }

    var t= JSON.stringify(data);

    var file=`{appFileRoot}/FileServer/default/凭证号与附件关联/${corpid}/${ym}/${pzh}.json` ; 
    saveToFile( file, t ) ;

     

}


id: 6653549299327550ff10dabe
scriptid: 60ac750d5db2f5d22859c4c0
tablename: app_script
clientip: 60.177.72.27
username: sa
createdate: 2024.05.26 23:28:28.000
script:
/*
凭证中的某个附件移除，并还原到待归档图片池中
  1 记录移除
  2 移到 待归档图片池中
  3  几个标记数据还愿

*/

function main(arg) {

    println( arg); 
    var p = JSON.parse(arg);
    var id = p.id;  // dzpz_pzfj.id 
    println( "id="+ id);

   
    //得到当前操作员待归档图片对应的GGUID
    var t = runTask("get_dzpz_imgpool_id_of_current_user", {});
    var gguid = JSON.parse(t).gguid;


    var dzpz_pzfj_ds = newDataStore("", "select * from dzpz_pzfj "); //凭证附件
    dzpz_pzfj_ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    dzpz_pzfj_ds.retrieve(" id='"+ id+"' ");
    var pzid = dzpz_pzfj_ds.getString(0,"gguid");
    println( "select  verifierid  from dzpz_pz  where id='"+pzid+"' ");
    if( getIntFromSQL("select  verifierid  from dzpz_pz  where id='"+pzid+"' ")>0)
    {
        println("已审核，禁止删除附件");
     return { success:false, message:'凭证已审核，禁止删除'};
    }
    

    //待归档的图片池
    var dzpz_imgpool_fileupload_ds = newDataStore("", "select * from dzpz_imgpool_fileupload");
    dzpz_imgpool_fileupload_ds.setUpdateProperty("dzpz_imgpool_fileupload", "id", "*", "id");


    var row = dzpz_imgpool_fileupload_ds.insertRow(9999);

    cloneRow(dzpz_pzfj_ds, dzpz_imgpool_fileupload_ds, row);

    //数据调整


    dzpz_imgpool_fileupload_ds.setValue(row, "groupname", '附件');  //把类型改成 凭证

    dzpz_imgpool_fileupload_ds.setValue(row, "gguid", gguid);
    dzpz_imgpool_fileupload_ds.setValue(row, "tablename", "dzpz_imgpool");
    

    //删除源
    //当 
    dzpz_pzfj_ds.deleteRow(0);

    //更新附件数量
    
    dzpz_pzfj_ds.executeAfterUpdate(" update dzpz_pz  set attachmentcount= (select count(*) from dzpz_pzfj where gguid='"+ pzid+"' ) , "+
     " fj = (select count(*) from dzpz_pzfj where gguid='"+ pzid+"' and groupname='附件' ) , "+
     " pz = (select count(*) from dzpz_pzfj where gguid='"+ pzid+"' and groupname='凭证'  )  "+
               "   where id='"+ pzid+"' ");

    var err = '' + updateAll(dzpz_pzfj_ds, dzpz_imgpool_fileupload_ds);

    if (err == '') return { success: true };
    println(err);

    runTask("归档信息保存到文件中", {pzid: pzid} );

    return { success: false, message: err };

}

function cloneRow(dzpz_pzfj_ds, dzpz_imgpool_fileupload_ds, row) {
    for (var i = 0; i < dzpz_pzfj_ds.getColumnCount(); i++) {
        var col = dzpz_pzfj_ds.getColumnName(i);
        var value = dzpz_pzfj_ds.getValue(0, i);
        dzpz_imgpool_fileupload_ds.setValue(row, col, value);
    }
}


id: 6653549299327550ff10dada
scriptid: 60d0840b0c749ebb22855746
tablename: app_script
clientip: 60.177.72.27
username: sa
createdate: 2024.05.26 23:29:41.000
script:
function main(arg) {
    println(arg );
    var p = JSON.parse(arg);
    var id = p.id;
    var overwrite = p.overwrite;

    // info2 是手工调整顺序后的序号 ，如果没有手工调整顺序，那么info2应该都是null , 
    // 这样，如果手工调整了顺序，那么以手工调整后的顺序来排序，
    //否则以(groupname优先排序，它通常是“凭证”，“附件”) 凭证排在前，附件排在后 ，同类型（groupname）文件的按原始日期来排序，

    var tds = newDataStore("", "select pzh , corpid from dzpz_pz where id='" + id + "'");
    tds.retrieve();
    var pzh = tds.getString(0, "pzh");
    var corpid = tds.getString(0, "corpid");
    println("pzh="+ pzh);
    println("corpid="+ corpid);

    var url = getStringFromSQL("select url_img  from basic_corp_seal a , basic_corp b where a.gguid=b.gguid and a.groupname='电子印章' and b.code= '" + corpid + "' ");
    println( url);

    if( getIntFromSQL("select count(*) from dzpz_pzfj where gguid='"+id+"' ")==0)
    {
        return {sccess:false, message: "凭证归档信息丢失,禁止重新生成pdf "};
         
    }

    runTask("归档信息保存到文件中", {pzid: id} );

    //把附件打包成一个PDF ,生成pdf不要加水印，水印是在下载时临时加上去的
    return createArchive("dzpz", 
         id,
        "info2 asc , groupname , info1 asc ",  //附件排序规则
        overwrite, //是否强行重新生成
        '', //水印 。生成pdf不要加水印，水印是在下载时临时加上去的
        {
            left: 20,
            top: 20,
            url:  url
        },  //左上角加一个印章图片
        pzh //右上角把凭证号打上，便于查看
    );


}


id: 6653549299327550ff10dae3
scriptid: 66534a9199327550ff10da2c
tablename: app_script
clientip: 60.177.72.27
username: sa
createdate: 2024.05.26 23:32:06.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
     

     println( arg);
    var p= JSON.parse(arg);
   
    var id= p.pzid;
     

    var  dzpz_pz_ds = newDataStore("", "select * from dzpz_pz ");  //凭证主记录
    dzpz_pz_ds.retrieve(" id='"+  id+"' ");

    var  dzpz_pzfj_ds = newDataStore("", "select * from dzpz_pzfj "); //凭证附件
    var n = dzpz_pzfj_ds.retrieve(" gguid='"+  id+"' "); 
    
 
    var corpid= dzpz_pz_ds.getValue(0,"corpid");
    var ym  = dzpz_pz_ds.getString(0,"ym");
    var pzh  = dzpz_pz_ds.getString(0,"pzh");

    var data={};
    data.dzpz_pz = dzpz_pz_ds.getJSONRow( 0, true);
    data.dzpz_pzfj =[];
    for( var i=0;i< n;  i++)
    {
        data.dzpz_pzfj.push( JSON.parse( dzpz_pzfj_ds.getJSONRow(i,true) ));
    }

    var t= JSON.stringify(data);

    var file=`{appFileRoot}/FileServer/default/凭证号与附件关联/${corpid}/${ym}/${pzh}.json` ; 
    saveToFile( file, t ) ;

     

}


id: 665570a699327550ff10db5e
scriptid: 60a31c3c5db27838e0c012a2
tablename: app_template
clientip: 60.176.231.168
username: sa
createdate: 2024.05.28 14:04:29.000
script:
var labelDataInited = false;

/**
 * 表单初始化完成后，执行此事件
 */
//@comment (group=表单事件,caption=表单初始化完成)
function formOpen() {
    book.showTabOnWhere = "top";
    $dzpz_pzbq_ds.reset();
    var s = $dzpz_pz_ds.getString(0, "labeldata");
    if (s == '') s = "{}";
    var data = JSON.parse(s);
    if (typeof (data) != 'object') data = {};
    for (var name in data) {
        var value = data[name];
        if (['凭证号', '记帐期'].contains(name)) continue;
        var row = $dzpz_pzbq_ds.insertRow(999);
        $dzpz_pzbq_ds.setValue(row, { name: name, value: value });
    }
    labelDataInited = true;

    if( $app_archive_ds.getString(0,"url_img")!='' &&  $dzpz_pzfj_ds.rowCount == 0)
    {
        book.sheet3.getBrick('cb_repair').visible=true;
    }else{
        book.sheet3.getBrick('cb_repair').visible=false;
    }

}

//图片控件初始化之前的处理，注入参数
function imageGridlyBeforeInit(sheet, name, data) {
    sheet.getBrick(name).config.uploadButtonDisabled = true;
    sheet.getBrick(name).config.deleteButtonDisabled = true;
}

/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    if (dsname == 'dzpz_pzbq') {
        rebuildLabel();
    }
}


function rebuildLabel() {
    if (!labelDataInited) return;
    var label = { '凭证号': $dzpz_pz_ds.getString(0, "pzh"), '记帐期': $dzpz_pz_ds.getInt(0, "ym") };
    for (var i = 0; i < $dzpz_pzbq_ds.rowCount; i++) {
        var name = $dzpz_pzbq_ds.getString(i, "name");

        var value = $dzpz_pzbq_ds.getString(i, "value");
        if (name == '') continue;
        label[name] = value;
    }

    $dzpz_pz_ds.setValue(0, "labeldata", JSON.stringify(label));

}


function cb_download_onClick() {
    packageGo('download');
}


function cb_view_onClick() {
    var url = $app_archive_ds.getString(0, "url_img");
    if (url != '') {
        openWindow(url);
    } else {
        packageGo('view');
    }
 
}

function packageGo(action) {
    var ret = JSON.parse(runTask("pz_image2pdf", {
        id: currentGUID(),
        overwrite: false  //如果已存在，不要重新生成
    }));
    console.dir(ret);
    if (ret.success) {
        smartRetrieve(book.sheet0, "app_archive");
        let url = ret.data.url_img;
        if (action == 'download') url = url.replace('action=view', 'action=download');
        url = safeURL(safeURL(url)); //没有其它意思，就是测试一下safeURL的幂等性
        console.info(url);
        openWindow(url);
    } else {
        $.alert(ret.message);
    }
}


id: 665570a699327550ff10db62
scriptid: 60a31c3c5db27838e0c012a2
tablename: app_template
clientip: 60.176.231.168
username: sa
createdate: 2024.05.28 14:14:29.000
script:
var labelDataInited = false;

/**
 * 表单初始化完成后，执行此事件
 */
//@comment (group=表单事件,caption=表单初始化完成)
function formOpen() {
    book.showTabOnWhere = "top";
    $dzpz_pzbq_ds.reset();
    var s = $dzpz_pz_ds.getString(0, "labeldata");
    if (s == '') s = "{}";
    var data = JSON.parse(s);
    if (typeof (data) != 'object') data = {};
    for (var name in data) {
        var value = data[name];
        if (['凭证号', '记帐期'].contains(name)) continue;
        var row = $dzpz_pzbq_ds.insertRow(999);
        $dzpz_pzbq_ds.setValue(row, { name: name, value: value });
    }
    labelDataInited = true;

    

}

/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver()
{
    if( $app_archive_ds.getString(0,"url_img")!='' &&  $dzpz_pzfj_ds.rowCount == 0)
    {
        book.sheet3.getBrick('cb_repair').visible=true;
    }else{
        book.sheet3.getBrick('cb_repair').visible=false;
    }

}


//图片控件初始化之前的处理，注入参数
function imageGridlyBeforeInit(sheet, name, data) {
    sheet.getBrick(name).config.uploadButtonDisabled = true;
    sheet.getBrick(name).config.deleteButtonDisabled = true;
}

/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    if (dsname == 'dzpz_pzbq') {
        rebuildLabel();
    }
}


function rebuildLabel() {
    if (!labelDataInited) return;
    var label = { '凭证号': $dzpz_pz_ds.getString(0, "pzh"), '记帐期': $dzpz_pz_ds.getInt(0, "ym") };
    for (var i = 0; i < $dzpz_pzbq_ds.rowCount; i++) {
        var name = $dzpz_pzbq_ds.getString(i, "name");

        var value = $dzpz_pzbq_ds.getString(i, "value");
        if (name == '') continue;
        label[name] = value;
    }

    $dzpz_pz_ds.setValue(0, "labeldata", JSON.stringify(label));

}


function cb_download_onClick() {
    packageGo('download');
}


function cb_view_onClick() {
    var url = $app_archive_ds.getString(0, "url_img");
    if (url != '') {
        openWindow(url);
    } else {
        packageGo('view');
    }
 
}

function packageGo(action) {
    var ret = JSON.parse(runTask("pz_image2pdf", {
        id: currentGUID(),
        overwrite: false  //如果已存在，不要重新生成
    }));
    console.dir(ret);
    if (ret.success) {
        smartRetrieve(book.sheet0, "app_archive");
        let url = ret.data.url_img;
        if (action == 'download') url = url.replace('action=view', 'action=download');
        url = safeURL(safeURL(url)); //没有其它意思，就是测试一下safeURL的幂等性
        console.info(url);
        openWindow(url);
    } else {
        $.alert(ret.message);
    }
}


id: 665576d199327550ff10db66
scriptid: 60a31c3c5db27838e0c012a2
tablename: app_template
clientip: 60.176.231.168
username: sa
createdate: 2024.05.28 14:16:50.000
script:
var labelDataInited = false;

/**
 * 表单初始化完成后，执行此事件
 */
//@comment (group=表单事件,caption=表单初始化完成)
function formOpen() {
    book.showTabOnWhere = "top";
    $dzpz_pzbq_ds.reset();
    var s = $dzpz_pz_ds.getString(0, "labeldata");
    if (s == '') s = "{}";
    var data = JSON.parse(s);
    if (typeof (data) != 'object') data = {};
    for (var name in data) {
        var value = data[name];
        if (['凭证号', '记帐期'].contains(name)) continue;
        var row = $dzpz_pzbq_ds.insertRow(999);
        $dzpz_pzbq_ds.setValue(row, { name: name, value: value });
    }
    labelDataInited = true;

    

}

/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver()
{
    if( $app_archive_ds.getString(0,"url_img")!='' &&  $dzpz_pzfj_ds.rowCount == 0)
    {
        book.sheet3.getBrick('cb_repair').visible=true;
    }else{
        book.sheet3.getBrick('cb_repair').visible=false;
    }

}


//图片控件初始化之前的处理，注入参数
function imageGridlyBeforeInit(sheet, name, data) {
    sheet.getBrick(name).config.uploadButtonDisabled = true;
    sheet.getBrick(name).config.deleteButtonDisabled = true;
}

/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    if (dsname == 'dzpz_pzbq') {
        rebuildLabel();
    }
}


function rebuildLabel() {
    if (!labelDataInited) return;
    var label = { '凭证号': $dzpz_pz_ds.getString(0, "pzh"), '记帐期': $dzpz_pz_ds.getInt(0, "ym") };
    for (var i = 0; i < $dzpz_pzbq_ds.rowCount; i++) {
        var name = $dzpz_pzbq_ds.getString(i, "name");

        var value = $dzpz_pzbq_ds.getString(i, "value");
        if (name == '') continue;
        label[name] = value;
    }

    $dzpz_pz_ds.setValue(0, "labeldata", JSON.stringify(label));

}


function cb_download_onClick() {
    packageGo('download');
}


function cb_view_onClick() {
    var url = $app_archive_ds.getString(0, "url_img");
    if (url != '') {
        openWindow(url);
    } else {
        packageGo('view');
    }
 
}

function packageGo(action) {
    var ret = JSON.parse(runTask("pz_image2pdf", {
        id: currentGUID(),
        overwrite: false  //如果已存在，不要重新生成
    }));
    console.dir(ret);
    if (ret.success) {
        smartRetrieve(book.sheet0, "app_archive");
        let url = ret.data.url_img;
        if (action == 'download') url = url.replace('action=view', 'action=download');
        url = safeURL(safeURL(url)); //没有其它意思，就是测试一下safeURL的幂等性
        console.info(url);
        openWindow(url);
    } else {
        $.alert(ret.message);
    }
}


function cb_repair_onClick()
{
    $confirm("提示","当存在pdf文件，而丢失相应的图片文件时，可以通过此功能来恢复图片清单，确信要修复吗?",function()
    {

    });
}


id: 665576d199327550ff10db6a
scriptid: 60a31c3c5db27838e0c012a2
tablename: app_template
clientip: 60.176.231.168
username: sa
createdate: 2024.05.28 14:19:39.000
script:
var labelDataInited = false;

/**
 * 表单初始化完成后，执行此事件
 */
//@comment (group=表单事件,caption=表单初始化完成)
function formOpen() {
    book.showTabOnWhere = "top";
    $dzpz_pzbq_ds.reset();
    var s = $dzpz_pz_ds.getString(0, "labeldata");
    if (s == '') s = "{}";
    var data = JSON.parse(s);
    if (typeof (data) != 'object') data = {};
    for (var name in data) {
        var value = data[name];
        if (['凭证号', '记帐期'].contains(name)) continue;
        var row = $dzpz_pzbq_ds.insertRow(999);
        $dzpz_pzbq_ds.setValue(row, { name: name, value: value });
    }
    labelDataInited = true;

    

}

/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver()
{
    if( $app_archive_ds.getString(0,"url_img")!='' &&  $dzpz_pzfj_ds.rowCount == 0)
    {
        book.sheet3.getBrick('cb_repair').visible=true;
    }else{
        book.sheet3.getBrick('cb_repair').visible=false;
    }

}


//图片控件初始化之前的处理，注入参数
function imageGridlyBeforeInit(sheet, name, data) {
    sheet.getBrick(name).config.uploadButtonDisabled = true;
    sheet.getBrick(name).config.deleteButtonDisabled = true;
}

/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    if (dsname == 'dzpz_pzbq') {
        rebuildLabel();
    }
}


function rebuildLabel() {
    if (!labelDataInited) return;
    var label = { '凭证号': $dzpz_pz_ds.getString(0, "pzh"), '记帐期': $dzpz_pz_ds.getInt(0, "ym") };
    for (var i = 0; i < $dzpz_pzbq_ds.rowCount; i++) {
        var name = $dzpz_pzbq_ds.getString(i, "name");

        var value = $dzpz_pzbq_ds.getString(i, "value");
        if (name == '') continue;
        label[name] = value;
    }

    $dzpz_pz_ds.setValue(0, "labeldata", JSON.stringify(label));

}


function cb_download_onClick() {
    packageGo('download');
}


function cb_view_onClick() {
    var url = $app_archive_ds.getString(0, "url_img");
    if (url != '') {
        openWindow(url);
    } else {
        packageGo('view');
    }
 
}

function packageGo(action) {
    var ret = JSON.parse(runTask("pz_image2pdf", {
        id: currentGUID(),
        overwrite: false  //如果已存在，不要重新生成
    }));
    console.dir(ret);
    if (ret.success) {
        smartRetrieve(book.sheet0, "app_archive");
        let url = ret.data.url_img;
        if (action == 'download') url = url.replace('action=view', 'action=download');
        url = safeURL(safeURL(url)); //没有其它意思，就是测试一下safeURL的幂等性
        console.info(url);
        openWindow(url);
    } else {
        $.alert(ret.message);
    }
}


function cb_repair_onClick()
{
    $confirm("提示","当存在pdf文件，而丢失相应的图片文件时，可以通过此功能来恢复图片清单，确信要修复吗?",function()
    {
        back_repair( $app_archive_ds.getString(0,"url_img") , function()
        {
            $dzpz_pzfj_ds.smartRetrieve(  ) ;
        });
    });
}


id: 665576d199327550ff10db70
scriptid: 60a31c3c5db27838e0c0129e
tablename: app_script
clientip: 60.176.231.168
username: sa
createdate: 2024.05.28 14:30:38.000
script:
function getImageList1()
{
    return getImageList("凭证");
}
function getImageList2()
{
    return getImageList("附件");
}


//@comment (group=,caption=得到待归档的图片清单,needRightControl=true)
function getImageList(groupName) {
     
    //排除掉回收站的图片
    var sql= "select * from  dzpz_pzfj  where  gguid='" + currentGUID() + "'  and groupname='"+groupName+"'  order by info2 asc, groupname, info1 asc ";
    println( sql);
    var ds = newDataStore("", sql); // info1 是客户端文件创建的时间，以它排序
    var n = ds.retrieve();
   
    var ret = [];
    for (var i = 0; i < n; i++) {
        ret.push(JSON.parse(ds.getJSONRow(i, true)));
    }

    return  { success:true,  data:ret};

}


/**
 * 点击删除单据，在执行单据删除语句后（但尚未提交），系统在服务端触发本事件
 *
 *  可以在本事件中，注入一些操作，返回一组SQL，这此SQL与单据删除操作将在一个事务中执行。
 *
 * @notice 注意：本事件在服务端执行，不要试图访问任何前端UI信息。不要直接执行对数据库的写操作，如果需要
 * 请在返回值中返回这些语句，让系统把它们与单据删除并在一个事务中执行。
 *
 * @param gguid  要删除单据主记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据删除过程中的各个事件之间传递数据。各个事件
 * 脚本虽然写在一起，但它们是按顺序在服务器上分开独立执行的，各个事件可能并不是在同一个脚本
 * 引擎中执行，如果对session做了写的操作，必须在返回值中
 * 将它返回，系统将它做为参数传递到下一个事件中
 *
 * @return   返回值是这样的一个JSON对象
 * { success:true,
 *    message:'' ,
 *    sql: { "default" : [ sql1, sql2 ...] ,
 *            "dbpool2": [sql1, sql2 ...]
 *         }
 * }
 *   success=true 表示继续允许执行删除单据操作 ， 并且在执行单据删除后，执行一些SQL语句。sql定义的规则：
 *   { 连接池名称1: [ SQL数组] , 连接池名称2: [ SQL数组] ....  }
 *
 *
 * 如果 success 设置成false ,则在 message中放置错误提示信息，此时整个单据删除操作被立即终止
 *
 */
//@comment (group=单据,caption=单据删除语句执行后)
function afterBillDeleteOnServer(gguid, session) {

    //注意：此时单据尚未开始删除，仍可用 gguid 来查询单据数据

    var objectName = getStringFromSQL( `select objectname from app_archive where gguid='${gguid}'` ) ;
    println( objectName +" 将被删除");
    deleteFileOnFileServer (  1 , objectName ) ;
    var sql= `delete from app_archive where gguid='${gguid}'` ;
    println( sql);

    return {
        success: true,
        message: "",
        session: session,
        sql: {"default": [sql]}  // 归档信息删除
    };

}


function back_repair( url , pzh )
{
    var result= extractImagesFromPDF(url ,pzh , 4*1024); //小于 4k的忽略 ，pdf中每个图片右上角有一个凭证号的小图片，这个需要排除掉

    println( result);
    var imgs= result.imgs;
    for( var  i=0;i< imgs.length; i++)
    {
        uploadFile( {
                        file: imgs[i].path , 
                        serverIndex:2 ,
                        tablename:'dzpz_pz',
                        gguid:currentGUID(),
                        groupname: i==0?"凭证":"附件",
                        info1: imgs[i].createDate
        }   ) ;
    }


}


id: 665576d199327550ff10db76
scriptid: 60a31c3c5db27838e0c0129e
tablename: app_script
clientip: 60.176.231.168
username: sa
createdate: 2024.05.28 14:30:45.000
script:
function getImageList1() {
    return getImageList("凭证");
}
function getImageList2() {
    return getImageList("附件");
}


//@comment (group=,caption=得到待归档的图片清单,needRightControl=true)
function getImageList(groupName) {

    //排除掉回收站的图片
    var sql = "select * from  dzpz_pzfj  where  gguid='" + currentGUID() + "'  and groupname='" + groupName + "'  order by info2 asc, groupname, info1 asc ";
    println(sql);
    var ds = newDataStore("", sql); // info1 是客户端文件创建的时间，以它排序
    var n = ds.retrieve();

    var ret = [];
    for (var i = 0; i < n; i++) {
        ret.push(JSON.parse(ds.getJSONRow(i, true)));
    }

    return { success: true, data: ret };

}


/**
 * 点击删除单据，在执行单据删除语句后（但尚未提交），系统在服务端触发本事件
 *
 *  可以在本事件中，注入一些操作，返回一组SQL，这此SQL与单据删除操作将在一个事务中执行。
 *
 * @notice 注意：本事件在服务端执行，不要试图访问任何前端UI信息。不要直接执行对数据库的写操作，如果需要
 * 请在返回值中返回这些语句，让系统把它们与单据删除并在一个事务中执行。
 *
 * @param gguid  要删除单据主记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据删除过程中的各个事件之间传递数据。各个事件
 * 脚本虽然写在一起，但它们是按顺序在服务器上分开独立执行的，各个事件可能并不是在同一个脚本
 * 引擎中执行，如果对session做了写的操作，必须在返回值中
 * 将它返回，系统将它做为参数传递到下一个事件中
 *
 * @return   返回值是这样的一个JSON对象
 * { success:true,
 *    message:'' ,
 *    sql: { "default" : [ sql1, sql2 ...] ,
 *            "dbpool2": [sql1, sql2 ...]
 *         }
 * }
 *   success=true 表示继续允许执行删除单据操作 ， 并且在执行单据删除后，执行一些SQL语句。sql定义的规则：
 *   { 连接池名称1: [ SQL数组] , 连接池名称2: [ SQL数组] ....  }
 *
 *
 * 如果 success 设置成false ,则在 message中放置错误提示信息，此时整个单据删除操作被立即终止
 *
 */
//@comment (group=单据,caption=单据删除语句执行后)
function afterBillDeleteOnServer(gguid, session) {

    //注意：此时单据尚未开始删除，仍可用 gguid 来查询单据数据

    var objectName = getStringFromSQL(`select objectname from app_archive where gguid='${gguid}'`);
    println(objectName + " 将被删除");
    deleteFileOnFileServer(1, objectName);
    var sql = `delete from app_archive where gguid='${gguid}'`;
    println(sql);

    return {
        success: true,
        message: "",
        session: session,
        sql: { "default": [sql] }  // 归档信息删除
    };

}


function back_repair(url, pzh) {
    var result = extractImagesFromPDF(url, pzh, 4 * 1024); //小于 4k的忽略 ，pdf中每个图片右上角有一个凭证号的小图片，这个需要排除掉

    println(result);
    var imgs = result.imgs;
    for (var i = 0; i < imgs.length; i++) {
        uploadFile({
            file: imgs[i].path,
            serverIndex: 2,
            tablename: 'dzpz_pz',
            gguid: currentGUID(),
            groupname: i == 0 ? "凭证" : "附件",
            info1: imgs[i].createDate
        });
    }


}


id: 665576d199327550ff10db7c
scriptid: 60a31c3c5db27838e0c0129e
tablename: app_script
clientip: 60.176.231.168
username: sa
createdate: 2024.05.28 14:31:36.000
script:
function getImageList1() {
    return getImageList("凭证");
}
function getImageList2() {
    return getImageList("附件");
}


//@comment (group=,caption=得到待归档的图片清单,needRightControl=true)
function getImageList(groupName) {

    //排除掉回收站的图片
    var sql = "select * from  dzpz_pzfj  where  gguid='" + currentGUID() + "'  and groupname='" + groupName + "'  order by info2 asc, groupname, info1 asc ";
    println(sql);
    var ds = newDataStore("", sql); // info1 是客户端文件创建的时间，以它排序
    var n = ds.retrieve();

    var ret = [];
    for (var i = 0; i < n; i++) {
        ret.push(JSON.parse(ds.getJSONRow(i, true)));
    }

    return { success: true, data: ret };

}


/**
 * 点击删除单据，在执行单据删除语句后（但尚未提交），系统在服务端触发本事件
 *
 *  可以在本事件中，注入一些操作，返回一组SQL，这此SQL与单据删除操作将在一个事务中执行。
 *
 * @notice 注意：本事件在服务端执行，不要试图访问任何前端UI信息。不要直接执行对数据库的写操作，如果需要
 * 请在返回值中返回这些语句，让系统把它们与单据删除并在一个事务中执行。
 *
 * @param gguid  要删除单据主记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据删除过程中的各个事件之间传递数据。各个事件
 * 脚本虽然写在一起，但它们是按顺序在服务器上分开独立执行的，各个事件可能并不是在同一个脚本
 * 引擎中执行，如果对session做了写的操作，必须在返回值中
 * 将它返回，系统将它做为参数传递到下一个事件中
 *
 * @return   返回值是这样的一个JSON对象
 * { success:true,
 *    message:'' ,
 *    sql: { "default" : [ sql1, sql2 ...] ,
 *            "dbpool2": [sql1, sql2 ...]
 *         }
 * }
 *   success=true 表示继续允许执行删除单据操作 ， 并且在执行单据删除后，执行一些SQL语句。sql定义的规则：
 *   { 连接池名称1: [ SQL数组] , 连接池名称2: [ SQL数组] ....  }
 *
 *
 * 如果 success 设置成false ,则在 message中放置错误提示信息，此时整个单据删除操作被立即终止
 *
 */
//@comment (group=单据,caption=单据删除语句执行后)
function afterBillDeleteOnServer(gguid, session) {

    //注意：此时单据尚未开始删除，仍可用 gguid 来查询单据数据

    var objectName = getStringFromSQL(`select objectname from app_archive where gguid='${gguid}'`);
    println(objectName + " 将被删除");
    deleteFileOnFileServer(1, objectName);
    var sql = `delete from app_archive where gguid='${gguid}'`;
    println(sql);

    return {
        success: true,
        message: "",
        session: session,
        sql: { "default": [sql] }  // 归档信息删除
    };

}


function back_repair(url, pzh) {
    var result = extractImagesFromPDF(url, pzh, 4 * 1024); //小于 4k的忽略 ，pdf中每个图片右上角有一个凭证号的小图片，这个需要排除掉

    println(result);
    var imgs = result.imgs;
    for (var i = 0; i < imgs.length; i++) {
        uploadFile({
            file: imgs[i].path,
            serverIndex: 2,
            tablename: 'dzpz_pz',
            gguid: currentGUID(),
            groupname: i == 0 ? "凭证" : "附件",
            info1: imgs[i].createDate
        });
    }

    return imgs.length;  

}


id: 665576d199327550ff10db80
scriptid: 60a31c3c5db27838e0c012a2
tablename: app_template
clientip: 60.176.231.168
username: sa
createdate: 2024.05.28 14:32:41.000
script:
var labelDataInited = false;

/**
 * 表单初始化完成后，执行此事件
 */
//@comment (group=表单事件,caption=表单初始化完成)
function formOpen() {
    book.showTabOnWhere = "top";
    $dzpz_pzbq_ds.reset();
    var s = $dzpz_pz_ds.getString(0, "labeldata");
    if (s == '') s = "{}";
    var data = JSON.parse(s);
    if (typeof (data) != 'object') data = {};
    for (var name in data) {
        var value = data[name];
        if (['凭证号', '记帐期'].contains(name)) continue;
        var row = $dzpz_pzbq_ds.insertRow(999);
        $dzpz_pzbq_ds.setValue(row, { name: name, value: value });
    }
    labelDataInited = true;

    

}

/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver()
{
    if( $app_archive_ds.getString(0,"url_img")!='' &&  $dzpz_pzfj_ds.rowCount == 0)
    {
        book.sheet3.getBrick('cb_repair').visible=true;
    }else{
        book.sheet3.getBrick('cb_repair').visible=false;
    }

}


//图片控件初始化之前的处理，注入参数
function imageGridlyBeforeInit(sheet, name, data) {
    sheet.getBrick(name).config.uploadButtonDisabled = true;
    sheet.getBrick(name).config.deleteButtonDisabled = true;
}

/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    if (dsname == 'dzpz_pzbq') {
        rebuildLabel();
    }
}


function rebuildLabel() {
    if (!labelDataInited) return;
    var label = { '凭证号': $dzpz_pz_ds.getString(0, "pzh"), '记帐期': $dzpz_pz_ds.getInt(0, "ym") };
    for (var i = 0; i < $dzpz_pzbq_ds.rowCount; i++) {
        var name = $dzpz_pzbq_ds.getString(i, "name");

        var value = $dzpz_pzbq_ds.getString(i, "value");
        if (name == '') continue;
        label[name] = value;
    }

    $dzpz_pz_ds.setValue(0, "labeldata", JSON.stringify(label));

}


function cb_download_onClick() {
    packageGo('download');
}


function cb_view_onClick() {
    var url = $app_archive_ds.getString(0, "url_img");
    if (url != '') {
        openWindow(url);
    } else {
        packageGo('view');
    }
 
}

function packageGo(action) {
    var ret = JSON.parse(runTask("pz_image2pdf", {
        id: currentGUID(),
        overwrite: false  //如果已存在，不要重新生成
    }));
    console.dir(ret);
    if (ret.success) {
        smartRetrieve(book.sheet0, "app_archive");
        let url = ret.data.url_img;
        if (action == 'download') url = url.replace('action=view', 'action=download');
        url = safeURL(safeURL(url)); //没有其它意思，就是测试一下safeURL的幂等性
        console.info(url);
        openWindow(url);
    } else {
        $.alert(ret.message);
    }
}


function cb_repair_onClick()
{
    $confirm("提示","当存在pdf文件，而丢失相应的图片文件时，可以通过此功能来恢复图片清单，确信要修复吗?",function()
    {
        back_repair( $app_archive_ds.getString(0,"url_img") , function( ret )
        {
            $dzpz_pz_ds.setValue( 0,"attachmentcount", ret);
            $dzpz_pz_ds.setValue( 0,"pz", 1);
            $dzpz_pz_ds.setValue( 0,"fj", ret -1);
            
            $dzpz_pzfj_ds.smartRetrieve(  ) ;
        });
    });
}


id: 665576d199327550ff10db84
scriptid: 60a31c3c5db27838e0c012a2
tablename: app_template
clientip: 60.176.231.168
username: sa
createdate: 2024.05.28 14:32:53.000
script:
var labelDataInited = false;

/**
 * 表单初始化完成后，执行此事件
 */
//@comment (group=表单事件,caption=表单初始化完成)
function formOpen() {
    book.showTabOnWhere = "top";
    $dzpz_pzbq_ds.reset();
    var s = $dzpz_pz_ds.getString(0, "labeldata");
    if (s == '') s = "{}";
    var data = JSON.parse(s);
    if (typeof (data) != 'object') data = {};
    for (var name in data) {
        var value = data[name];
        if (['凭证号', '记帐期'].contains(name)) continue;
        var row = $dzpz_pzbq_ds.insertRow(999);
        $dzpz_pzbq_ds.setValue(row, { name: name, value: value });
    }
    labelDataInited = true;

    

}

/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver()
{
    if( $app_archive_ds.getString(0,"url_img")!='' &&  $dzpz_pzfj_ds.rowCount == 0)
    {
        book.sheet3.getBrick('cb_repair').visible=true;
    }else{
        book.sheet3.getBrick('cb_repair').visible=false;
    }

}


//图片控件初始化之前的处理，注入参数
function imageGridlyBeforeInit(sheet, name, data) {
    sheet.getBrick(name).config.uploadButtonDisabled = true;
    sheet.getBrick(name).config.deleteButtonDisabled = true;
}

/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    if (dsname == 'dzpz_pzbq') {
        rebuildLabel();
    }
}


function rebuildLabel() {
    if (!labelDataInited) return;
    var label = { '凭证号': $dzpz_pz_ds.getString(0, "pzh"), '记帐期': $dzpz_pz_ds.getInt(0, "ym") };
    for (var i = 0; i < $dzpz_pzbq_ds.rowCount; i++) {
        var name = $dzpz_pzbq_ds.getString(i, "name");

        var value = $dzpz_pzbq_ds.getString(i, "value");
        if (name == '') continue;
        label[name] = value;
    }

    $dzpz_pz_ds.setValue(0, "labeldata", JSON.stringify(label));

}


function cb_download_onClick() {
    packageGo('download');
}


function cb_view_onClick() {
    var url = $app_archive_ds.getString(0, "url_img");
    if (url != '') {
        openWindow(url);
    } else {
        packageGo('view');
    }
 
}

function packageGo(action) {
    var ret = JSON.parse(runTask("pz_image2pdf", {
        id: currentGUID(),
        overwrite: false  //如果已存在，不要重新生成
    }));
    console.dir(ret);
    if (ret.success) {
        smartRetrieve(book.sheet0, "app_archive");
        let url = ret.data.url_img;
        if (action == 'download') url = url.replace('action=view', 'action=download');
        url = safeURL(safeURL(url)); //没有其它意思，就是测试一下safeURL的幂等性
        console.info(url);
        openWindow(url);
    } else {
        $.alert(ret.message);
    }
}


function cb_repair_onClick()
{
    $confirm("提示","当存在pdf文件，而丢失相应的图片文件时，可以通过此功能来恢复图片清单，确信要修复吗?",function()
    {
        back_repair( $app_archive_ds.getString(0,"url_img") , function( ret )
        {
            $dzpz_pz_ds.setValue( 0,"attachmentcount", ret);
            $dzpz_pz_ds.setValue( 0,"pz", 1);
            $dzpz_pz_ds.setValue( 0,"fj", ret -1);
            form.save(false);
            $dzpz_pzfj_ds.smartRetrieve(  ) ;
        });
    });
}


id: 665576d199327550ff10db9f
scriptid: 60a31c3c5db27838e0c0129e
tablename: app_script
clientip: 60.177.72.27
username: sa
createdate: 2024.05.28 21:20:55.000
script:
function getImageList1() {
    return getImageList("凭证");
}
function getImageList2() {
    return getImageList("附件");
}


//@comment (group=,caption=得到待归档的图片清单,needRightControl=true)
function getImageList(groupName) {

    //排除掉回收站的图片
    var sql = "select * from  dzpz_pzfj  where  gguid='" + currentGUID() + "'  and groupname='" + groupName + "'  order by info2 asc, groupname, info1 asc ";
    println(sql);
    var ds = newDataStore("", sql); // info1 是客户端文件创建的时间，以它排序
    var n = ds.retrieve();

    var ret = [];
    for (var i = 0; i < n; i++) {
        ret.push(JSON.parse(ds.getJSONRow(i, true)));
    }

    return { success: true, data: ret };

}


/**
 * 点击删除单据，在执行单据删除语句后（但尚未提交），系统在服务端触发本事件
 *
 *  可以在本事件中，注入一些操作，返回一组SQL，这此SQL与单据删除操作将在一个事务中执行。
 *
 * @notice 注意：本事件在服务端执行，不要试图访问任何前端UI信息。不要直接执行对数据库的写操作，如果需要
 * 请在返回值中返回这些语句，让系统把它们与单据删除并在一个事务中执行。
 *
 * @param gguid  要删除单据主记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据删除过程中的各个事件之间传递数据。各个事件
 * 脚本虽然写在一起，但它们是按顺序在服务器上分开独立执行的，各个事件可能并不是在同一个脚本
 * 引擎中执行，如果对session做了写的操作，必须在返回值中
 * 将它返回，系统将它做为参数传递到下一个事件中
 *
 * @return   返回值是这样的一个JSON对象
 * { success:true,
 *    message:'' ,
 *    sql: { "default" : [ sql1, sql2 ...] ,
 *            "dbpool2": [sql1, sql2 ...]
 *         }
 * }
 *   success=true 表示继续允许执行删除单据操作 ， 并且在执行单据删除后，执行一些SQL语句。sql定义的规则：
 *   { 连接池名称1: [ SQL数组] , 连接池名称2: [ SQL数组] ....  }
 *
 *
 * 如果 success 设置成false ,则在 message中放置错误提示信息，此时整个单据删除操作被立即终止
 *
 */
//@comment (group=单据,caption=单据删除语句执行后)
function afterBillDeleteOnServer(gguid, session) {

    //注意：此时单据尚未开始删除，仍可用 gguid 来查询单据数据

    var objectName = getStringFromSQL(`select objectname from app_archive where gguid='${gguid}'`);
    println(objectName + " 将被删除");
    deleteFileOnFileServer(1, objectName);
    var sql = `delete from app_archive where gguid='${gguid}'`;
    println(sql);

    return {
        success: true,
        message: "",
        session: session,
        sql: { "default": [sql] }  // 归档信息删除
    };

}


function back_repair(url, pzh) {
    var result = extractImagesFromPDF( safeURL(url), pzh, 4 * 1024); //小于 4k的忽略 ，pdf中每个图片右上角有一个凭证号的小图片，这个需要排除掉

    println(result);
    var imgs = result.imgs;
    for (var i = 0; i < imgs.length; i++) {
        uploadFile({
            file: imgs[i].path,
            serverIndex: 2,
            tablename: 'dzpz_pz',
            gguid: currentGUID(),
            groupname: i == 0 ? "凭证" : "附件",
            info1: imgs[i].createDate
        });
    }

    return imgs.length;  

}


id: 665576d199327550ff10dba5
scriptid: 60a31c3c5db27838e0c0129e
tablename: app_script
clientip: 60.177.72.27
username: sa
createdate: 2024.05.28 21:22:14.000
script:
function getImageList1() {
    return getImageList("凭证");
}
function getImageList2() {
    return getImageList("附件");
}


//@comment (group=,caption=得到待归档的图片清单,needRightControl=true)
function getImageList(groupName) {

    //排除掉回收站的图片
    var sql = "select * from  dzpz_pzfj  where  gguid='" + currentGUID() + "'  and groupname='" + groupName + "'  order by info2 asc, groupname, info1 asc ";
    println(sql);
    var ds = newDataStore("", sql); // info1 是客户端文件创建的时间，以它排序
    var n = ds.retrieve();

    var ret = [];
    for (var i = 0; i < n; i++) {
        ret.push(JSON.parse(ds.getJSONRow(i, true)));
    }

    return { success: true, data: ret };

}


/**
 * 点击删除单据，在执行单据删除语句后（但尚未提交），系统在服务端触发本事件
 *
 *  可以在本事件中，注入一些操作，返回一组SQL，这此SQL与单据删除操作将在一个事务中执行。
 *
 * @notice 注意：本事件在服务端执行，不要试图访问任何前端UI信息。不要直接执行对数据库的写操作，如果需要
 * 请在返回值中返回这些语句，让系统把它们与单据删除并在一个事务中执行。
 *
 * @param gguid  要删除单据主记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据删除过程中的各个事件之间传递数据。各个事件
 * 脚本虽然写在一起，但它们是按顺序在服务器上分开独立执行的，各个事件可能并不是在同一个脚本
 * 引擎中执行，如果对session做了写的操作，必须在返回值中
 * 将它返回，系统将它做为参数传递到下一个事件中
 *
 * @return   返回值是这样的一个JSON对象
 * { success:true,
 *    message:'' ,
 *    sql: { "default" : [ sql1, sql2 ...] ,
 *            "dbpool2": [sql1, sql2 ...]
 *         }
 * }
 *   success=true 表示继续允许执行删除单据操作 ， 并且在执行单据删除后，执行一些SQL语句。sql定义的规则：
 *   { 连接池名称1: [ SQL数组] , 连接池名称2: [ SQL数组] ....  }
 *
 *
 * 如果 success 设置成false ,则在 message中放置错误提示信息，此时整个单据删除操作被立即终止
 *
 */
//@comment (group=单据,caption=单据删除语句执行后)
function afterBillDeleteOnServer(gguid, session) {

    //注意：此时单据尚未开始删除，仍可用 gguid 来查询单据数据

    var objectName = getStringFromSQL(`select objectname from app_archive where gguid='${gguid}'`);
    println(objectName + " 将被删除");
    deleteFileOnFileServer(1, objectName);
    var sql = `delete from app_archive where gguid='${gguid}'`;
    println(sql);

    return {
        success: true,
        message: "",
        session: session,
        sql: { "default": [sql] }  // 归档信息删除
    };

}


function back_repair(url, pzh) {
    var result = extractImagesFromPDF( safeURL(url), pzh, 4 * 1024); //小于 4k的忽略 ，pdf中每个图片右上角有一个凭证号的小图片，这个需要排除掉
    println("currentguid= "+ currentGUID(  ) );
    println(result);
    var imgs = result.imgs;
    for (var i = 0; i < imgs.length; i++) {
        uploadFile({
            file: imgs[i].path,
            serverIndex: 2,
            tablename: 'dzpz_pz',
            gguid: currentGUID(),
            groupname: i == 0 ? "凭证" : "附件",
            info1: imgs[i].createDate
        });
    }

    return imgs.length;  

}


id: 665576d199327550ff10dbab
scriptid: 60a31c3c5db27838e0c0129e
tablename: app_script
clientip: 60.177.72.27
username: sa
createdate: 2024.05.28 23:32:38.000
script:
function getImageList1() {
    return getImageList("凭证");
}
function getImageList2() {
    return getImageList("附件");
}


//@comment (group=,caption=得到待归档的图片清单,needRightControl=true)
function getImageList(groupName) {

    //排除掉回收站的图片
    var sql = "select * from  dzpz_pzfj  where  gguid='" + currentGUID() + "'  and groupname='" + groupName + "'  order by info2 asc, groupname, info1 asc ";
    println(sql);
    var ds = newDataStore("", sql); // info1 是客户端文件创建的时间，以它排序
    var n = ds.retrieve();

    var ret = [];
    for (var i = 0; i < n; i++) {
        ret.push(JSON.parse(ds.getJSONRow(i, true)));
    }

    return { success: true, data: ret };

}


/**
 * 点击删除单据，在执行单据删除语句后（但尚未提交），系统在服务端触发本事件
 *
 *  可以在本事件中，注入一些操作，返回一组SQL，这此SQL与单据删除操作将在一个事务中执行。
 *
 * @notice 注意：本事件在服务端执行，不要试图访问任何前端UI信息。不要直接执行对数据库的写操作，如果需要
 * 请在返回值中返回这些语句，让系统把它们与单据删除并在一个事务中执行。
 *
 * @param gguid  要删除单据主记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据删除过程中的各个事件之间传递数据。各个事件
 * 脚本虽然写在一起，但它们是按顺序在服务器上分开独立执行的，各个事件可能并不是在同一个脚本
 * 引擎中执行，如果对session做了写的操作，必须在返回值中
 * 将它返回，系统将它做为参数传递到下一个事件中
 *
 * @return   返回值是这样的一个JSON对象
 * { success:true,
 *    message:'' ,
 *    sql: { "default" : [ sql1, sql2 ...] ,
 *            "dbpool2": [sql1, sql2 ...]
 *         }
 * }
 *   success=true 表示继续允许执行删除单据操作 ， 并且在执行单据删除后，执行一些SQL语句。sql定义的规则：
 *   { 连接池名称1: [ SQL数组] , 连接池名称2: [ SQL数组] ....  }
 *
 *
 * 如果 success 设置成false ,则在 message中放置错误提示信息，此时整个单据删除操作被立即终止
 *
 */
//@comment (group=单据,caption=单据删除语句执行后)
function afterBillDeleteOnServer(gguid, session) {

    //注意：此时单据尚未开始删除，仍可用 gguid 来查询单据数据

    var objectName = getStringFromSQL(`select objectname from app_archive where gguid='${gguid}'`);
    println(objectName + " 将被删除");
    deleteFileOnFileServer(1, objectName);
    var sql = `delete from app_archive where gguid='${gguid}'`;
    println(sql);

    return {
        success: true,
        message: "",
        session: session,
        sql: { "default": [sql] }  // 归档信息删除
    };

}


function back_repair(url, pzh) {
    var result = extractImagesFromPDF( safeURL(url), pzh, 4 * 1024); //小于 4k的忽略 ，pdf中每个图片右上角有一个凭证号的小图片，这个需要排除掉
    println("currentguid= "+ currentGUID(  ) );
    println(result);
    var imgs = result.imgs;
    for (var i = 0; i < imgs.length; i++) {
        uploadFile({
            file: imgs[i].path,
            serverIndex: 2,
            logTable: 'dzpz_pzfj',
            tablename: 'dzpz_pz',
            gguid: currentGUID(),
            groupname: i == 0 ? "凭证" : "附件",
            info1: imgs[i].createDate
        });
    }

    return imgs.length;  

}


id: 665576d199327550ff10dbb0
scriptid: 60a31c3c5db27838e0c012a2
tablename: app_template
clientip: 60.177.72.27
username: sa
createdate: 2024.05.28 23:33:43.000
script:
var labelDataInited = false;

/**
 * 表单初始化完成后，执行此事件
 */
//@comment (group=表单事件,caption=表单初始化完成)
function formOpen() {
    book.showTabOnWhere = "top";
    $dzpz_pzbq_ds.reset();
    var s = $dzpz_pz_ds.getString(0, "labeldata");
    if (s == '') s = "{}";
    var data = JSON.parse(s);
    if (typeof (data) != 'object') data = {};
    for (var name in data) {
        var value = data[name];
        if (['凭证号', '记帐期'].contains(name)) continue;
        var row = $dzpz_pzbq_ds.insertRow(999);
        $dzpz_pzbq_ds.setValue(row, { name: name, value: value });
    }
    labelDataInited = true;

    

}

/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver()
{
    if( $app_archive_ds.getString(0,"url_img")!='' &&  $dzpz_pzfj_ds.rowCount == 0)
    {
        book.sheet3.getBrick('cb_repair').visible=true;
    }else{
        book.sheet3.getBrick('cb_repair').visible=false;
    }

}


//图片控件初始化之前的处理，注入参数
function imageGridlyBeforeInit(sheet, name, data) {
    sheet.getBrick(name).config.uploadButtonDisabled = true;
    sheet.getBrick(name).config.deleteButtonDisabled = true;
}

/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    if (dsname == 'dzpz_pzbq') {
        rebuildLabel();
    }
}


function rebuildLabel() {
    if (!labelDataInited) return;
    var label = { '凭证号': $dzpz_pz_ds.getString(0, "pzh"), '记帐期': $dzpz_pz_ds.getInt(0, "ym") };
    for (var i = 0; i < $dzpz_pzbq_ds.rowCount; i++) {
        var name = $dzpz_pzbq_ds.getString(i, "name");

        var value = $dzpz_pzbq_ds.getString(i, "value");
        if (name == '') continue;
        label[name] = value;
    }

    $dzpz_pz_ds.setValue(0, "labeldata", JSON.stringify(label));

}


function cb_download_onClick() {
    packageGo('download');
}


function cb_view_onClick() {
    var url = $app_archive_ds.getString(0, "url_img");
    if (url != '') {
        openWindow(url);
    } else {
        packageGo('view');
    }
 
}

function packageGo(action) {
    var ret = JSON.parse(runTask("pz_image2pdf", {
        id: currentGUID(),
        overwrite: false  //如果已存在，不要重新生成
    }));
    console.dir(ret);
    if (ret.success) {
        smartRetrieve(book.sheet0, "app_archive");
        let url = ret.data.url_img;
        if (action == 'download') url = url.replace('action=view', 'action=download');
        url = safeURL(safeURL(url)); //没有其它意思，就是测试一下safeURL的幂等性
        console.info(url);
        openWindow(url);
    } else {
        $.alert(ret.message);
    }
}


function cb_repair_onClick()
{
    $confirm("提示","当存在pdf文件，而丢失相应的图片文件时，可以通过此功能来恢复图片清单，确信要修复吗?",function()
    {
        toastr.show("正在分析图片...");
        back_repair( $app_archive_ds.getString(0,"url_img") , function( ret )
        {
            $dzpz_pz_ds.setValue( 0,"attachmentcount", ret);
            $dzpz_pz_ds.setValue( 0,"pz", 1);
            $dzpz_pz_ds.setValue( 0,"fj", ret -1);
            form.save(false);
            $dzpz_pzfj_ds.smartRetrieve(  ) ;
            toastr.hie();
            toastr.info("分析完成");
            
        });
    });
}


id: 665576d199327550ff10dbb4
scriptid: 60a31c3c5db27838e0c012a2
tablename: app_template
clientip: 60.177.72.27
username: sa
createdate: 2024.05.28 23:39:44.000
script:
var labelDataInited = false;

/**
 * 表单初始化完成后，执行此事件
 */
//@comment (group=表单事件,caption=表单初始化完成)
function formOpen() {
    book.showTabOnWhere = "top";
    $dzpz_pzbq_ds.reset();
    var s = $dzpz_pz_ds.getString(0, "labeldata");
    if (s == '') s = "{}";
    var data = JSON.parse(s);
    if (typeof (data) != 'object') data = {};
    for (var name in data) {
        var value = data[name];
        if (['凭证号', '记帐期'].contains(name)) continue;
        var row = $dzpz_pzbq_ds.insertRow(999);
        $dzpz_pzbq_ds.setValue(row, { name: name, value: value });
    }
    labelDataInited = true;

    

}

/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver()
{
    if( $app_archive_ds.getString(0,"url_img")!='' &&  $dzpz_pzfj_ds.rowCount == 0)
    {
        book.sheet0.getBrick('cb_repair').visible=true;
        book.sheet3.getBrick('cb_repair').visible=true;
        
    }else{
        book.sheet0.getBrick('cb_repair').visible=false;
        book.sheet3.getBrick('cb_repair').visible=true;
        
    }

}


//图片控件初始化之前的处理，注入参数
function imageGridlyBeforeInit(sheet, name, data) {
    sheet.getBrick(name).config.uploadButtonDisabled = true;
    sheet.getBrick(name).config.deleteButtonDisabled = true;
}

/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    if (dsname == 'dzpz_pzbq') {
        rebuildLabel();
    }
}


function rebuildLabel() {
    if (!labelDataInited) return;
    var label = { '凭证号': $dzpz_pz_ds.getString(0, "pzh"), '记帐期': $dzpz_pz_ds.getInt(0, "ym") };
    for (var i = 0; i < $dzpz_pzbq_ds.rowCount; i++) {
        var name = $dzpz_pzbq_ds.getString(i, "name");

        var value = $dzpz_pzbq_ds.getString(i, "value");
        if (name == '') continue;
        label[name] = value;
    }

    $dzpz_pz_ds.setValue(0, "labeldata", JSON.stringify(label));

}


function cb_download_onClick() {
    packageGo('download');
}


function cb_view_onClick() {
    var url = $app_archive_ds.getString(0, "url_img");
    if (url != '') {
        openWindow(url);
    } else {
        packageGo('view');
    }
 
}

function packageGo(action) {
    var ret = JSON.parse(runTask("pz_image2pdf", {
        id: currentGUID(),
        overwrite: false  //如果已存在，不要重新生成
    }));
    console.dir(ret);
    if (ret.success) {
        smartRetrieve(book.sheet0, "app_archive");
        let url = ret.data.url_img;
        if (action == 'download') url = url.replace('action=view', 'action=download');
        url = safeURL(safeURL(url)); //没有其它意思，就是测试一下safeURL的幂等性
        console.info(url);
        openWindow(url);
    } else {
        $.alert(ret.message);
    }
}


function cb_repair_onClick()
{
    $confirm("提示","当存在pdf文件，而丢失相应的图片文件时，可以通过此功能来恢复图片清单，确信要修复吗?",function()
    {
        toastr.show("正在分析图片...");
        back_repair( $app_archive_ds.getString(0,"url_img") , function( ret )
        {
            $dzpz_pz_ds.setValue( 0,"attachmentcount", ret);
            $dzpz_pz_ds.setValue( 0,"pz", 1);
            $dzpz_pz_ds.setValue( 0,"fj", ret -1);
            form.save(false);
            $dzpz_pzfj_ds.smartRetrieve(  ) ;
            toastr.hie();
            toastr.info("分析完成");
            
        });
    });
}


id: 665576d199327550ff10dbb8
scriptid: 60a31c3c5db27838e0c012a2
tablename: app_template
clientip: 60.177.72.27
username: sa
createdate: 2024.05.28 23:40:55.000
script:
var labelDataInited = false;

/**
 * 表单初始化完成后，执行此事件
 */
//@comment (group=表单事件,caption=表单初始化完成)
function formOpen() {
    book.showTabOnWhere = "top";
    $dzpz_pzbq_ds.reset();
    var s = $dzpz_pz_ds.getString(0, "labeldata");
    if (s == '') s = "{}";
    var data = JSON.parse(s);
    if (typeof (data) != 'object') data = {};
    for (var name in data) {
        var value = data[name];
        if (['凭证号', '记帐期'].contains(name)) continue;
        var row = $dzpz_pzbq_ds.insertRow(999);
        $dzpz_pzbq_ds.setValue(row, { name: name, value: value });
    }
    labelDataInited = true;

    

}

/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver()
{
    if( $app_archive_ds.getString(0,"url_img")!='' &&  $dzpz_pzfj_ds.rowCount == 0)
    {
        book.sheet0.getBrick('cb_repair').visible=true;
        book.sheet3.getBrick('cb_repair').visible=true;
        
    }else{
        book.sheet0.getBrick('cb_repair').visible=false;
        book.sheet3.getBrick('cb_repair').visible=true;
        
    }

}


//图片控件初始化之前的处理，注入参数
function imageGridlyBeforeInit(sheet, name, data) {
    sheet.getBrick(name).config.uploadButtonDisabled = true;
    sheet.getBrick(name).config.deleteButtonDisabled = true;
}

/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    if (dsname == 'dzpz_pzbq') {
        rebuildLabel();
    }
}


function rebuildLabel() {
    if (!labelDataInited) return;
    var label = { '凭证号': $dzpz_pz_ds.getString(0, "pzh"), '记帐期': $dzpz_pz_ds.getInt(0, "ym") };
    for (var i = 0; i < $dzpz_pzbq_ds.rowCount; i++) {
        var name = $dzpz_pzbq_ds.getString(i, "name");

        var value = $dzpz_pzbq_ds.getString(i, "value");
        if (name == '') continue;
        label[name] = value;
    }

    $dzpz_pz_ds.setValue(0, "labeldata", JSON.stringify(label));

}


function cb_download_onClick() {
    packageGo('download');
}


function cb_view_onClick() {
    var url = $app_archive_ds.getString(0, "url_img");
    if (url != '') {
        openWindow(url);
    } else {
        packageGo('view');
    }
 
}

function packageGo(action) {
    var ret = JSON.parse(runTask("pz_image2pdf", {
        id: currentGUID(),
        overwrite: false  //如果已存在，不要重新生成
    }));
    console.dir(ret);
    if (ret.success) {
        smartRetrieve(book.sheet0, "app_archive");
        let url = ret.data.url_img;
        if (action == 'download') url = url.replace('action=view', 'action=download');
        url = safeURL(safeURL(url)); //没有其它意思，就是测试一下safeURL的幂等性
        console.info(url);
        openWindow(url);
    } else {
        $.alert(ret.message);
    }
}


function cb_repair_onClick()
{
    $confirm("提示","当存在pdf文件，而丢失相应的图片文件时，可以通过此功能来恢复图片清单，确信要修复吗?",function()
    {
        toastr.show("正在分析图片...");
        back_repair( $app_archive_ds.getString(0,"url_img") , function( ret )
        {
            $dzpz_pz_ds.setValue( 0,"attachmentcount", ret);
            $dzpz_pz_ds.setValue( 0,"pz", 1);
            $dzpz_pz_ds.setValue( 0,"fj", ret -1);
            form.save(false);
            $dzpz_pzfj_ds.smartRetrieve(  ) ;
            toastr.hie();
            toastr.info("分析完成");
            form.loadBill( currentGUID());
            
        });
    });
}


id: 665576d199327550ff10dbc7
scriptid: 60a31c3c5db27838e0c012a2
tablename: app_template
clientip: 60.177.72.27
username: sa
createdate: 2024.05.28 23:48:39.000
script:
var labelDataInited = false;

/**
 * 表单初始化完成后，执行此事件
 */
//@comment (group=表单事件,caption=表单初始化完成)
function formOpen() {
    book.showTabOnWhere = "top";
    $dzpz_pzbq_ds.reset();
    var s = $dzpz_pz_ds.getString(0, "labeldata");
    if (s == '') s = "{}";
    var data = JSON.parse(s);
    if (typeof (data) != 'object') data = {};
    for (var name in data) {
        var value = data[name];
        if (['凭证号', '记帐期'].contains(name)) continue;
        var row = $dzpz_pzbq_ds.insertRow(999);
        $dzpz_pzbq_ds.setValue(row, { name: name, value: value });
    }
    labelDataInited = true;

    

}

/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver()
{
    if( $app_archive_ds.getString(0,"url_img")!='' &&  $dzpz_pzfj_ds.rowCount == 0)
    {
        book.sheet0.getBrick('cb_repair').visible=true;
        book.sheet3.getBrick('cb_repair').visible=true;
        
    }else{
        book.sheet0.getBrick('cb_repair').visible=false;
        book.sheet3.getBrick('cb_repair').visible=true;
        
    }

}


//图片控件初始化之前的处理，注入参数
function imageGridlyBeforeInit(sheet, name, data) {
    sheet.getBrick(name).config.uploadButtonDisabled = true;
    sheet.getBrick(name).config.deleteButtonDisabled = true;
}

/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    if (dsname == 'dzpz_pzbq') {
        rebuildLabel();
    }
}


function rebuildLabel() {
    if (!labelDataInited) return;
    var label = { '凭证号': $dzpz_pz_ds.getString(0, "pzh"), '记帐期': $dzpz_pz_ds.getInt(0, "ym") };
    for (var i = 0; i < $dzpz_pzbq_ds.rowCount; i++) {
        var name = $dzpz_pzbq_ds.getString(i, "name");

        var value = $dzpz_pzbq_ds.getString(i, "value");
        if (name == '') continue;
        label[name] = value;
    }

    $dzpz_pz_ds.setValue(0, "labeldata", JSON.stringify(label));

}


function cb_download_onClick() {
    packageGo('download');
}


function cb_view_onClick() {
    var url = $app_archive_ds.getString(0, "url_img");
    if (url != '') {
        openWindow(url);
    } else {
        packageGo('view');
    }
 
}

function packageGo(action) {
    var ret = JSON.parse(runTask("pz_image2pdf", {
        id: currentGUID(),
        overwrite: false  //如果已存在，不要重新生成
    }));
    console.dir(ret);
    if (ret.success) {
        smartRetrieve(book.sheet0, "app_archive");
        let url = ret.data.url_img;
        if (action == 'download') url = url.replace('action=view', 'action=download');
        url = safeURL(safeURL(url)); //没有其它意思，就是测试一下safeURL的幂等性
        console.info(url);
        openWindow(url);
    } else {
        $.alert(ret.message);
    }
}


function cb_repair_onClick()
{
    $confirm("提示","当存在pdf文件，而丢失相应的图片文件时，可以通过此功能来恢复图片清单，确信要修复吗?",function()
    {
        toastr.show("正在分析图片...");
        back_repair( $app_archive_ds.getString(0,"url_img") , function( ret )
        {
            $dzpz_pz_ds.setValue( 0,"attachmentcount", ret);
            $dzpz_pz_ds.setValue( 0,"pz", 1);
            $dzpz_pz_ds.setValue( 0,"fj", ret -1);
            form.save(false);
            $dzpz_pzfj_ds.smartRetrieve(  ) ;
            toastr.hie();
            toastr.info("分析完成");
            window.history.go(0);
            
        });
    });
}


id: 665e742099327550ff10ddf9
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 12:17:06.000
script:
function cb_import_onClick()
{
    inputBox(  "提示", "请将凭证号粘贴在此", "","" , function(val){alert(val);}, false ,{} , 10);
}


id: 665e742099327550ff10ddfd
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 13:20:19.000
script:
function cb_import_onClick()
{
    inputBox(  "提示", "请将凭证号粘贴在此", "","" , function(val){
         back_import_pzh(val , function()
         {
             $pz_yjd_pzh_ds.smartRetrieve(   ) ;
         });
         }, false ,{} , 10);
}


id: 665e742099327550ff10de18
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 13:24:16.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd ( flow , node , gguid  ) {
    // println( flow.id) ; //流程定义的ID
    println( gguid+"工作结束了");

    runSQL("",  `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true); 
}




function back_import_pzh( s)
{
    var t= s.split(/[\s]/);
    for( var i=0;i< t.length; i++)
    {
        var pzh= t[i].trim();
        if( pzh=='') continue;
        var newid= newGuid(   ) ;
        var gguid= currentGUID(  ) ;
        runSQL("",`insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') ` ,true);
    }
    
}


id: 665e742099327550ff10de1c
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 13:27:45.000
script:
function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        back_import_pzh(val, function () {
            $pz_yjd_pzh_ds.smartRetrieve();
        });
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        back_build_sum(function () {
            $pz_yjdex_ds.smartRetrieve();
        });
    });

}


id: 665ea74799327550ff10de22
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 13:34:00.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd ( flow , node , gguid  ) {
    // println( flow.id) ; //流程定义的ID
    println( gguid+"工作结束了");

    runSQL("",  `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true); 
}




function back_import_pzh( s)
{
    var t= s.split(/[\s]/);
    for( var i=0;i< t.length; i++)
    {
        var pzh= t[i].trim();
        if( pzh=='') continue;
        var newid= newGuid(   ) ;
        var gguid= currentGUID(  ) ;
        runSQL("",`insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') ` ,true);
    }

}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum()
{

    var gguid= currentGUID(  ) ;
    var sql= `
    
SELECT
    MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
  COUNT(*) AS c 
FROM
  (
    SELECT
      pzh,
      @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
      @prev_number := pzh 
    FROM
      pz_yjd_pzh,
      (SELECT @group_id := 0, @prev_number := NULL) AS vars 
			where  gguid= ${gguid}
    ORDER BY
      pzh 
  ) AS subquery
GROUP BY
  group_id;
    
    ` ;
    var tds=newDataStore("",sql);
    var n= tds.retrieve();

    runSQL("",`delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds= newDataStore("","select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex','id','*','id'); 
    for( var i=0;i<n;i++)
    {
        var row= pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row , {id: newGuid(   ) , gguid: gguid , inner_xh: row+1 , 
                    pzh1:  tds.getString(i,"pzh1"),
                    pzh2:  tds.getString(i,"pzh2"),
                    pzs:  tds.getInt(i,"c") 
                    
                    
                    });
    }

    pz_yjdex_ds.update(true); 
    
}


id: 665ea74799327550ff10de28
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 13:35:32.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd ( flow , node , gguid  ) {
    // println( flow.id) ; //流程定义的ID
    println( gguid+"工作结束了");

    runSQL("",  `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true); 
}




function back_import_pzh( s)
{
    var t= s.split(/[\s]/);
    for( var i=0;i< t.length; i++)
    {
        var pzh= t[i].trim();
        if( pzh=='') continue;
        var newid= newGuid(   ) ;
        var gguid= currentGUID(  ) ;
        runSQL("",`insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') ` ,true);
    }

}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum()
{

    var gguid= currentGUID(  ) ;
    var sql= `
    
SELECT
    MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
  COUNT(*) AS c 
FROM
  (
    SELECT
      pzh,
      @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
      @prev_number := pzh 
    FROM
      pz_yjd_pzh,
      (SELECT @group_id := 0, @prev_number := NULL) AS vars 
			where  gguid= ${gguid}
    ORDER BY
      pzh 
  ) AS subquery
GROUP BY
  group_id;
    
    ` ;
    var tds=newDataStore("",sql);
    var n= tds.retrieve();

    runSQL("",`delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds= newDataStore("","select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex','id','*','id'); 
    for( var i=0;i<n;i++)
    {
        var row= pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row , {id: newGuid(   ) , gguid: gguid , inner_xh: row+1 , 
                    pzh1:  tds.getString(i,"pzh1"),
                    pzh2:  tds.getString(i,"pzh2"),
                    pzs:  tds.getInt(i,"c") 
                    
                    
                    });
    }

//
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `) ;
    pz_yjdex_ds.update(true); 

}


id: 665eab1099327550ff10deeb
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 13:50:09.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}




function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }

}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
    
SELECT
    MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
  COUNT(*) AS c 
FROM
  (
    SELECT
      pzh,
      @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
      @prev_number := pzh 
    FROM
      pz_yjd_pzh,
      (SELECT @group_id := 0, @prev_number := NULL) AS vars 
			where  gguid= ${gguid}
    ORDER BY
      pzh 
  ) AS subquery
GROUP BY
  group_id;
    
    ` ;
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);

}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 665eac7e99327550ff10dfdb
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 13:59:56.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}




function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }

}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
    
SELECT
    MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
  COUNT(*) AS c 
FROM
  (
    SELECT
      pzh,
      @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
      @prev_number := pzh 
    FROM
      pz_yjd_pzh,
      (SELECT @group_id := 0, @prev_number := NULL) AS vars 
			where  gguid= ${gguid}
    ORDER BY
      pzh 
  ) AS subquery
GROUP BY
  group_id;
    
    ` ;
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);
    $back_build_sum(gguid);

}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 665eac7e99327550ff10dfdf
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 14:00:15.000
script:
function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        back_import_pzh(val, function () {
            $pz_yjd_pzh_ds.smartRetrieve();
        });
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        back_build_sum(function () {
            form.loadBill( currentGUID());
        });
    });

}


id: 665eac7e99327550ff10dfea
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 14:03:05.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}




function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }

}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
    
SELECT
    MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
  COUNT(*) AS c 
FROM
  (
    SELECT
      pzh,
      @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
      @prev_number := pzh 
    FROM
      pz_yjd_pzh,
      (SELECT @group_id := 0, @prev_number := NULL) AS vars 
			where  gguid= ${gguid}
    ORDER BY
      pzh 
  ) AS subquery
GROUP BY
  group_id;
    
    ` ;
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);
    

}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 665eac7e99327550ff10dff3
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 14:04:35.000
script:
function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        back_import_pzh(val, function () {
            $pz_yjd_pzh_ds.smartRetrieve();
        });
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        back_build_sum(function () {
            form.loadBill(currentGUID(  ) );
        });
    });

}


id: 665eac7e99327550ff10dff9
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 14:06:05.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}




function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
        back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
    
SELECT
    MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
  COUNT(*) AS c 
FROM
  (
    SELECT
      pzh,
      @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
      @prev_number := pzh 
    FROM
      pz_yjd_pzh,
      (SELECT @group_id := 0, @prev_number := NULL) AS vars 
			where  gguid= ${gguid}
    ORDER BY
      pzh 
  ) AS subquery
GROUP BY
  group_id;
    
    ` ;
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);
    

}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 665eac7e99327550ff10e003
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 14:09:50.000
script:
function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        back_import_pzh(val, function () {
            $pz_yjd_pzh_ds.smartRetrieve();
        });
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        back_build_sum(function () {
            toastr.info("导入完成");
            $pz_yjd_ds.smartRetrieve( ) ;
            $pz_yjdex_ds.smartRetrieve( ) ;
            $pz_yjd_pzh_ds.smartRetrieve( ) ;

        });
    });

}


id: 665eac7e99327550ff10e009
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 14:11:11.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}




function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 665eac7e99327550ff10e00d
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 14:12:52.000
script:
function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        back_import_pzh(val, function () {
            $pz_yjd_pzh_ds.smartRetrieve();
        });
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在导入...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 665eac7e99327550ff10e011
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 14:17:46.000
script:
function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 665eb1b399327550ff10e015
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 14:18:27.000
script:
function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 665eb1b399327550ff10e019
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 14:19:42.000
script:
function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 665eb1b399327550ff10e01d
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 115.220.138.236
username: sa
createdate: 2024.06.04 14:20:01.000
script:
function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf836
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:42:34.000
script:
function cb_add(){
    
}


function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf83a
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:42:48.000
script:
//@comment (group=表单事件,caption=表单初始化完成)
function cb_add(){

}


function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf83e
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:45:41.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add(){

}


function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf842
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:46:53.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'right-center',
        at: 'right-center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 300, height: 400 });
    
book.sheet1.floatPanelClose();
}


function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf846
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:46:56.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'right-center',
        at: 'right-center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 300, height: 400 });
    
book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=添加凭证号)
function cb_add() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'right-center',
        at: 'right-center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 300, height: 400 });
    
book.sheet1.floatPanelClose();
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf84a
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:47:24.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'right-center',
        at: 'right-center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 300, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf84e
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:47:27.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'right-center',
        at: 'right-center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 300, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf852
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:47:53.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 300, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf857
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:48:59.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 300, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf85b
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:49:17.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz() {
    console.log('=============')
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 300, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf85f
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:49:23.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 300, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf863
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:49:30.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 300, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf867
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:49:45.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf86b
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:51:48.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
        memo: sheet.cells('memo').getValue(),
    }
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf86f
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:52:20.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue(''),
    sheet.cells('pzh1').setValue(''),
    sheet.cells('pzh2').setValue(''),
    sheet.cells('memo').setValue(''),
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
        memo: sheet.cells('memo').getValue(),
    }
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f07f29932df22f60cf873
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:52:30.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');
    sheet.cells('memo').setValue('');
    
    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
        memo: sheet.cells('memo').getValue(),
    }
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f0cea9932df22f60cf877
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:52:43.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');
    sheet.cells('memo').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
        memo: sheet.cells('memo').getValue(),
    }

    
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f0cea9932df22f60cf87b
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:53:01.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');
    sheet.cells('memo').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
        memo: sheet.cells('memo').getValue(),
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f0cea9932df22f60cf87f
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:53:07.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');
    sheet.cells('memo').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
        memo: sheet.cells('memo').getValue(),
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f0cea9932df22f60cf885
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:53:17.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data){
    
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f0cea9932df22f60cf88b
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:54:52.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data){
    var count = (data.pzh2/1)-(data.pzh1/1);

    if(count<=0){
        return {success:false, message:'终止凭证号要比起始凭证号大'}；
    }

    
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f0cea9932df22f60cf891
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:54:56.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data){
    var count = (data.pzh2/1)-(data.pzh1/1);

    if(count<=0){
        return {success:false, message:'终止凭证号要比起始凭证号大'};
    }


}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f0cea9932df22f60cf897
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:55:19.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data){
    var count = (data.pzh2/1)-(data.pzh1/1);

    if(count<=0){
        return {success:false, message:'终止凭证号要比起始凭证号大'};
    }

    for(var i=0;i<count;i++){
        
    }


}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f0cea9932df22f60cf89d
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:56:55.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);

    if (count <= 0) {
        return { success: false, message: '终止凭证号要比起始凭证号大' };
    }

    var gguid = currentGUID();
    for (var i = 0; i < count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, memo) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '${data.memo}') `, true);
    }


}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f0cea9932df22f60cf8a3
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:56:58.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);

    if (count <= 0) {
        return { success: false, message: '终止凭证号要比起始凭证号大' };
    }

    var gguid = currentGUID();
    for (var i = 0; i < count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, memo) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '${data.memo}') `, true);
    }

    back_build_sum();

}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f0cea9932df22f60cf8a9
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:58:06.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);

    if (count <= 0) {
        return { success: false, message: '终止凭证号要比起始凭证号大' };
    }

    var gguid = currentGUID();
    for (var i = 0; i < count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, memo) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '${data.memo}') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f0cea9932df22f60cf8af
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:58:26.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i < count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, memo) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '${data.memo}') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f0cea9932df22f60cf8b3
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 09:59:03.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');
    sheet.cells('memo').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
        memo: sheet.cells('memo').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        return  toastr.error( '终止凭证号要比起始凭证号大' ) ;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f0cea9932df22f60cf8bb
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:25:36.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');
    sheet.cells('memo').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
        memo: sheet.cells('memo').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' ) ;
        return  false
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f0cea9932df22f60cf8bf
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:25:37.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');
    sheet.cells('memo').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
        memo: sheet.cells('memo').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' ) ;
        return  false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f0cea9932df22f60cf8c3
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:25:48.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');
    sheet.cells('memo').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
        memo: sheet.cells('memo').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' ) ;
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f0cea9932df22f60cf8c7
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:25:51.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');
    sheet.cells('memo').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
        memo: sheet.cells('memo').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f15af9932df22f60cf9c3
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:31:06.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    runSQL('', `ALTER TABLE pz_yjdex MODIFY ny datetime`  ) 
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 669f15af9932df22f60cf9c9
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:31:18.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    runSQL('', `ALTER TABLE pz_yjdex MODIFY ny datetime`  ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 669f15af9932df22f60cfa00
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:31:59.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i < count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f15af9932df22f60cfa04
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:32:28.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f16bc9932df22f60cfa0a
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:34:36.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i < count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f16bc9932df22f60cfa16
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:37:01.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    return getListFromSQL2( '',  ` SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= 1098037835518190671
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 669f16bc9932df22f60cfa1c
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:37:15.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    return getListFromSQL2( '',  ` SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= 1098037835518190671
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 669f16bc9932df22f60cfa22
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:37:26.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i < count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f16bc9932df22f60cfa28
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:38:49.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f16bc9932df22f60cfa2e
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:39:23.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f16bc9932df22f60cfa32
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:46:51.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f16bc9932df22f60cfa36
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:47:03.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f16bc9932df22f60cfa3a
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:47:17.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

    book.sheet1.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {
    inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(val, function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
    }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f16bc9932df22f60cfa3e
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:47:30.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "浮动示例", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f16bc9932df22f60cfa42
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:47:46.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f16bc9932df22f60cfa46
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:47:50.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f16bc9932df22f60cfa4a
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:47:55.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f16bc9932df22f60cfa4e
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:48:14.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f16bc9932df22f60cfa52
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:48:40.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f16bc9932df22f60cfa58
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:49:16.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f16bc9932df22f60cfa5c
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 10:51:16.000
script:
//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 669f1c749932df22f60cfb4c
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 11:01:07.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '交办') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f1c749932df22f60cfb52
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 11:01:18.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '交办') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}', '交办') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f1c749932df22f60cfb58
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 11:01:37.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '交办') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}', '交办') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            billtype: '交办',
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f1dbc9932df22f60cfba5
scriptid: 669dc60c9932df22f60cad3b
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 11:04:46.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '交回') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}', '交回') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            billtype: '交回',
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f1dbc9932df22f60cfbd5
scriptid: 669dc6249932df22f60cc8cf
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 11:07:58.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '借阅') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}', '借阅') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            billtype: '借阅',
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f1dbc9932df22f60cfbe3
scriptid: 669dc6399932df22f60ce463
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 11:10:03.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '归还') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}', '归还') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            billtype: '归还',
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f66fa9932df22f60d001f
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 16:17:41.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary , a.state_jb=0   ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '交办') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}', '交办') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            billtype: '交办',
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f66fa9932df22f60d0025
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 16:18:01.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary , a.state_jb=0, a.state_jy=0   ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '交办') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}', '交办') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            billtype: '交办',
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f66fa9932df22f60d0033
scriptid: 669dc60c9932df22f60cad3b
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 16:18:24.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary, a.state_jb=1, a.state_jy=0     ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '交回') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}', '交回') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            billtype: '交回',
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f66fa9932df22f60d0039
scriptid: 669dc60c9932df22f60cad3b
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 16:18:34.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary, a.state_jb=1     ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '交回') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}', '交回') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            billtype: '交回',
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f67749932df22f60d0047
scriptid: 669dc6249932df22f60cc8cf
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 16:19:01.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary, a.state_jy=1     ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '借阅') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}', '借阅') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            billtype: '借阅',
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 669f67749932df22f60d0055
scriptid: 669dc6399932df22f60ce463
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.23 16:19:17.000
script:
/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");

    runSQL("", `UPDATE pzbmx a
            INNER JOIN  pz_yjdex b  inner join pz_yjd c on (b.gguid=c.gguid) 
             ON a.pzh  >= b.pzh1 and a.pzh<= b.pzh2 and b.gguid=${gguid}
            SET a.pos  = c.towhere , a.memo = c.summary , a.state_jy=0    ` , true);
}


function back_add_pzh(data) {
    var count = (data.pzh2 / 1) - (data.pzh1 / 1);


    var gguid = currentGUID();
    for (var i = 0; i <= count; i++) {
        var newid = newGuid();
        var pzh = (data.pzh1 / 1) + i;
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype) values ( ${newid} , ${gguid} , '${data.ny}', '${pzh}', '归还') `, true);
    }

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

    var t = data.pzh.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, ny, pzh, billtype ) values ( ${newid} , ${gguid} , '${data.ny}' , '${pzh}', '归还') `, true);
    }
    back_build_sum();
}

function back_import_pzh(s) {
    var t = s.split(/[\s]/);
    for (var i = 0; i < t.length; i++) {
        var pzh = t[i].trim();
        if (pzh == '') continue;
        var newid = newGuid();
        var gguid = currentGUID();
        runSQL("", `insert into  pz_yjd_pzh (id, gguid, pzh ) values ( ${newid} , ${gguid} , '${pzh}') `, true);
    }
    back_build_sum();
}

//  根据凭证号清单生成凭证号汇总信息 
function back_build_sum() {
    var gguid = currentGUID();
    $back_build_sum(gguid);
}


function $back_build_sum(gguid) {


    var sql = `
            
        SELECT
            MAX( ny ) as ny , MIN( pzh ) as pzh1 ,   MAX( pzh )  AS  pzh2,
        COUNT(*) AS c 
        FROM
        (
            SELECT
            ny,
            pzh,
            @group_id := IF( pzh  = @prev_number + 1, @group_id, @group_id + 1) AS group_id,
            @prev_number := pzh 
            FROM
            pz_yjd_pzh,
            (SELECT @group_id := 0, @prev_number := NULL) AS vars 
                    where  gguid= ${gguid}
            ORDER BY
            pzh 
        ) AS subquery
        GROUP BY
        group_id;
            
    ` ;

    println(sql);
    var tds = newDataStore("", sql);
    var n = tds.retrieve();

    runSQL("", `delete from  pz_yjdex where gguid= ${gguid} `, true);

    var pz_yjdex_ds = newDataStore("", "select * from pz_yjdex");
    pz_yjdex_ds.setUpdateProperty('pz_yjdex', 'id', '*', 'id');
    for (var i = 0; i < n; i++) {
        var row = pz_yjdex_ds.insertRow(9999);
        pz_yjdex_ds.setValue(row, {
            id: newGuid(), gguid: gguid, inner_xh: row + 1,
            billtype: '归还',
            ny: tds.getString(i, 'ny'),
            pzh1: tds.getString(i, "pzh1"),
            pzh2: tds.getString(i, "pzh2"),
            pzs: tds.getInt(i, "c")


        });
    }

    //
    pz_yjdex_ds.executeAfterUpdate(`update  pz_yjd  set pzs= (select count(*) from  pz_yjd_pzh where gguid= ${gguid} ) where   id= ${gguid}  `);
    pz_yjdex_ds.update(true);


}


/**
 * 单据点击保存，前端所有的操作被转译成3种操作:insert , delete , update ,
 *  并且可以在  beforeBillSaveOnServer 中返回一些SQL语句，可以在afterBillSaveOnServer中返回一些SQL语句
 *
 * 系统分别在需要的数据库连接中执行这些语句 ， 当所有语句执行成功后，事件被提交。一些细节如下 ：
 *
 * 1 如果单据中的表，属于不同的数据库连接，那么所有的SQL语句会以连接为单位，对语句进行批量执行
 * 2 这些语句的执行顺序是：对同一个数据库连接中的语句， 先执行 beforeBillSaveOnServer 中返回的SQL语句，再执行单据操作转译得到的SQL语句，
 *   再执行 afterBillSaveOnServer 中返回的SQL语句， 当多个（或一个）数据库连接执行完这些语句，且没有错误时，所有的数据库连接做提交，否则全部回滚
 * 3 不要在 beforeBillSaveOnServer 或 afterBillSaveOnServer 中直接执行数据库操作，而是返回SQL语句，让系统批量执行它们，并控制好事务
 * 4 当执行成功后，系统再执行事件函数  afterBillSaveSuccessfulOnServer 。 此事件中可以执行任意操作，它与单据保存事件结束后才被触发执行，
 *   与单据保存并不在一个事务中。
 *
 *
 * @param gguid  要删除记录的gguid ，等同于主表的id
 * @param session  一个JSON对象，用于在整个单据保存过程中的各个事件之间传递数据。本事件做为单据保存的最后一个事件，session对象在使用后将被丢弃
 *
 *
 * @return 本函数不需要返回值
 *
 */
//@comment (group=单据保存,caption=单据保存成功后)
function afterBillSaveSuccessfulOnServer(gguid, session) {

    $back_build_sum(gguid);
}


id: 66a1f1df993234357aee4107
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:38:12.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick(){

}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f1df993234357aee410f
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:39:10.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick(){
    let dlg= openDialog( "凭证资料导入" ,"bill" , "pzdj" , 700,500, {a:1,b:2} , "code=1&name=abc" , function(val){alert(val);});
}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f1df993234357aee4113
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:39:15.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick(){
    let dlg= openDialog( "凭证资料导入" ,"bill" , "pzdj" , 700,500, {} , "" , function(val){alert(val);});
}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f1df993234357aee4118
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:39:59.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick(){
    let dlg= openDialog( "凭证资料导入" ,"billlist" , "pzdj" , 700,500, {} , "" , function(val){alert(val);});
}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f1df993234357aee411c
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:40:13.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick(){
    let dlg= openDialog( "凭证资料导入" ,"billlist" , "pzdj" , 1000,500, {} , "" , function(val){alert(val);});
}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f365993234357aee4120
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:40:37.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick(){
    let dlg= openDialog( "凭证资料导入" ,"billlist" , "pzdj" , 1000,500, {} , "from_id="+currentGUID()  , function(val){alert(val);});
}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f365993234357aee4125
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:41:41.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick(){
    let dlg= floatDialog( "凭证资料导入" ,"billlist" , "pzdj" , 1000,500, {} , "from_id="+currentGUID()  , function(val){alert(val);});
}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f365993234357aee4129
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:41:59.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick(){
    let dlg= floatDialog( "凭证资料导入" ,"bill" , "pzdj" , 1000,500, {} , "from_id="+currentGUID()  , function(val){alert(val);});
}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f365993234357aee4139
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:42:53.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick(){
    let dlg= floatDialog( "凭证资料导入" ,"billlist" , "pzdj" , 1000,500, {} , "&listToolbarVisible=true&editToolbarVisible=true&from_id="+currentGUID()  , function(val){alert(val);});
}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f365993234357aee413d
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:42:58.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick(){
    let dlg= floatDialog( "凭证资料导入" ,"billlist" , "pzdj" , 1000,500, {} , "listToolbarVisible=true&editToolbarVisible=true&from_id="+currentGUID()  , function(val){alert(val);});
}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }
    
    if (data.pzh2 <= data.pzh1) {
        toastr.error( '终止凭证号要比起始凭证号大' );
        return false;
    }

    toastr.show("正在计算...");
        setTimeout(function () {
            back_add_pzh(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }
    

    toastr.show("正在计算...");
        setTimeout(function () {
            back_import_pzh_data(data, function () {
                toastr.hide();
                toastr.info("导入完成");
                // $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();
            });
        }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f365993234357aee4142
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:44:40.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick() {
    $.dialog({
        title: 'Text content!',
        boxWidth: '800px',
        useBootstrap: false,
        content: '<iframe  style="width:100%;height:400px; border:0" src="bill?id=pzdj&from_id='+currentGUID()+'"></iframe>'
    });
    // let dlg= floatDialog( "凭证资料导入" ,"billlist" , "pzdj" , 1000,500, {} , "listToolbarVisible=true&editToolbarVisible=true&from_id="+currentGUID()  , function(val){alert(val);});
}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

    toastr.show("正在计算...");
    setTimeout(function () {
        back_add_pzh(data, function () {
            toastr.hide();
            toastr.info("导入完成");
            // $pz_yjd_ds.smartRetrieve();
            $pz_yjdex_ds.smartRetrieve();
            $pz_yjd_pzh_ds.smartRetrieve();
            $q_pz_yjd_pzh_ds.smartRetrieve();
        });
    }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }


    toastr.show("正在计算...");
    setTimeout(function () {
        back_import_pzh_data(data, function () {
            toastr.hide();
            toastr.info("导入完成");
            // $pz_yjd_ds.smartRetrieve();
            $pz_yjdex_ds.smartRetrieve();
            $pz_yjd_pzh_ds.smartRetrieve();
            $q_pz_yjd_pzh_ds.smartRetrieve();
        });
    }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f365993234357aee4146
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:44:47.000
script:
//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick() {
    $.dialog({
        title: '凭证资料导入',
        boxWidth: '1000px',
        useBootstrap: false,
        content: '<iframe  style="width:100%;height:400px; border:0" src="bill?id=pzdj&from_id='+currentGUID()+'"></iframe>'
    });
    // let dlg= floatDialog( "凭证资料导入" ,"billlist" , "pzdj" , 1000,500, {} , "listToolbarVisible=true&editToolbarVisible=true&from_id="+currentGUID()  , function(val){alert(val);});
}


//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

    sheet.float('fa fa-cog', "添加凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 900, height: 400 });

}

//@comment (group=添加凭证号按钮,caption=取消)
function cb_cancel_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();
}

//@comment (group=添加凭证号按钮,caption=确认)
function cb_comfirn_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh1: sheet.cells('pzh1').getValue(),
        pzh2: sheet.cells('pzh2').getValue(),
    }

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

    toastr.show("正在计算...");
    setTimeout(function () {
        back_add_pzh(data, function () {
            toastr.hide();
            toastr.info("导入完成");
            // $pz_yjd_ds.smartRetrieve();
            $pz_yjdex_ds.smartRetrieve();
            $pz_yjd_pzh_ds.smartRetrieve();
            $q_pz_yjd_pzh_ds.smartRetrieve();
        });
    }, 100);
}

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

    sheet.float('fa fa-cog', "导入凭证号", {
        my: 'center',
        at: 'center',
        autoposition: 'down',
        offsetX: -5,
        offsetY: 5
    }, { width: 500, height: 400 });


    // inputBox("提示", "请将凭证号粘贴在此", "", "", function (val) {
    //     toastr.show("正在计算...");
    //     setTimeout(function () {
    //         back_import_pzh(val, function () {
    //             toastr.hide();
    //             toastr.info("导入完成");
    //             $pz_yjd_ds.smartRetrieve();
    //             $pz_yjdex_ds.smartRetrieve();
    //             $pz_yjd_pzh_ds.smartRetrieve();
    //             $q_pz_yjd_pzh_ds.smartRetrieve();
    //         });
    //     }, 100);
    // }, false, {}, 10);
}


//@comment (group=导入凭证号按钮,caption=取消)
function cb_cancel2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();
}

//@comment (group=导入凭证号按钮,caption=确认)
function cb_comfirn2_onClick() {
    var sheet = book.getWorkSheet('导入凭证号');
    sheet.floatPanelClose();

    var data = {
        ny: sheet.cells('ny').getValue(),
        pzh: sheet.cells('pzh').getValue(),
    }


    toastr.show("正在计算...");
    setTimeout(function () {
        back_import_pzh_data(data, function () {
            toastr.hide();
            toastr.info("导入完成");
            // $pz_yjd_ds.smartRetrieve();
            $pz_yjdex_ds.smartRetrieve();
            $pz_yjd_pzh_ds.smartRetrieve();
            $q_pz_yjd_pzh_ds.smartRetrieve();
        });
    }, 100);
}


function cb_buildsum_onClick() {
    $confirm("提示", "确信要根据凭证号清单生成凭证号汇总信息吗?", function () {
        toastr.show("正在计算...");
        setTimeout(function () {
            back_build_sum(function () {
                toastr.hide();
                toastr.info("导入完成");
                $pz_yjd_ds.smartRetrieve();
                $pz_yjdex_ds.smartRetrieve();
                $pz_yjd_pzh_ds.smartRetrieve();
                $q_pz_yjd_pzh_ds.smartRetrieve();

            });
        }, 100);

    });

}


id: 66a1f365993234357aee4158
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:48:27.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    return getListFromSQL2( '',  ` SELECT * from pz_yjd_pzh a left join pz_yjd b ` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a1f365993234357aee415e
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:48:48.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    return getListFromSQL2( '',  ` SELECT * from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a1f365993234357aee4170
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:51:40.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    return getListFromSQL2( '',  ` SELECT b.corpid, b.flow_instance_state, a.ny, a.pzh from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a1f365993234357aee4176
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 14:51:47.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    return getListFromSQL2( '',  ` SELECT b.corpid, b.flow_instance_state, a.ny, a.pzh, a.billtype from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a1f76f993234357aee41ba
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:36:30.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from pz_yjd_pzh a 
    left join pz_yjd b on a.gguid=b.gguid   where a.billtype='交办'
    join ( select max(lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh 
    from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid   where a.billtype='交办' group by corpid_ny_pzh ) c on a.lastmodifieddate=c.lastmodifieddate
    group by corpid_ny_pzh` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a1f76f993234357aee41c0
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:36:57.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from pz_yjd_pzh a 
    left join pz_yjd b on a.gguid=b.gguid   where a.billtype='交办'
    left join ( select max(lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh 
    from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid   where a.billtype='交办' group by corpid_ny_pzh ) c on a.lastmodifieddate=c.lastmodifieddate
    group by corpid_ny_pzh` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a1f76f993234357aee41c6
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:37:23.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from pz_yjd_pzh a 
    left join pz_yjd b on a.gguid=b.gguid   
    left join ( select max(lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh 
    from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid   where a.billtype='交办' group by corpid_ny_pzh ) c on a.lastmodifieddate=c.lastmodifieddate
    where a.billtype='交办'
    group by corpid_ny_pzh` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a1f76f993234357aee41cc
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:38:05.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    left join ( select max(lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh 
    from (select * from pz_yjd_pzh where billtype='交办')  a left join pz_yjd b on a.gguid=b.gguid   group by corpid_ny_pzh ) c on a.lastmodifieddate=c.lastmodifieddate
    group by corpid_ny_pzh` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a1f76f993234357aee41d2
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:38:59.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    left join ( select max(a.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh 
    from (select * from pz_yjd_pzh where billtype='交办')  a left join pz_yjd b on a.gguid=b.gguid   group by corpid_ny_pzh ) c on a.lastmodifieddate=c.lastmodifieddate
    group by corpid_ny_pzh` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a1f76f993234357aee41d8
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:39:54.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    left join ( select max(a1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
    from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) c on a.lastmodifieddate=c.lastmodifieddate
    group by corpid_ny_pzh` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a1f76f993234357aee41de
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:40:52.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a1f76f993234357aee41e4
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:41:43.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( a.ny, a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    
    // left join ( select max(a1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
    // from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) c on a.lastmodifieddate=c.lastmodifieddate

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a21e2b993234357aee41ea
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:43:08.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( a.ny, a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    // from (select * from pz_yjd_pzh where billtype='交办') a 
    // left join pz_yjd b on a.gguid=b.gguid   
    // group by corpid_ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    
    // left join ( select max(a1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
    // from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) c on a.lastmodifieddate=c.lastmodifieddate

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a21e2b993234357aee41f0
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:44:09.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select max(a1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
     from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    
    // left join ( select max(a1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
    // from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) c on a.lastmodifieddate=c.lastmodifieddate

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a21e2b993234357aee41f6
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:44:34.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select max(b1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
     from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    
    // left join ( select max(a1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
    // from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) c on a.lastmodifieddate=c.lastmodifieddate

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a21e2b993234357aee41fc
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:45:18.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select max(b1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
     from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    left join ( select max(b1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
    from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) c on a.lastmodifieddate=c.lastmodifieddate
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a21e2b993234357aee4202
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:45:21.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select max(b1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
     from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    left join ( select max(b1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
    from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) c on b.lastmodifieddate=c.lastmodifieddate
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a21e2b993234357aee4208
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:45:28.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    // return getListFromSQL2( '',  ` select max(b1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
    //  from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    left join ( select max(b1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
    from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) c on b.lastmodifieddate=c.lastmodifieddate
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a21e2b993234357aee420e
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:45:52.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    // return getListFromSQL2( '',  ` select max(b1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
    //  from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join pz_yjd b on a.gguid=b.gguid   
    left join ( select max(b1.lastmodifieddate) as lastmodifieddate,   CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
      from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) c on b.lastmodifieddate=c.lastmodifieddate
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a21e2b993234357aee4214
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:48:36.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select * from pz_yjd_pzh where billtype='交办'` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join (
        select a.* from pz_yjd a 
        left join ( select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) b 
        on b.lastmodifieddate=a.lastmodifieddate and a.corpid =b.corpid
    ) b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a21fc9993234357aee426f
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.25 17:50:38.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

runSQL('', `alter table pz_yjd_pzh alter column lastmodifieddate set default =currentDate()`  ) 
    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select * from pz_yjd_pzh where billtype='交办'` ) 

    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join (
        select a.* from pz_yjd a 
        left join ( select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) b 
        on b.lastmodifieddate=a.lastmodifieddate and a.corpid =b.corpid
    ) b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a22a7a993295696042f489
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.26 09:06:09.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

runSQL('', `alter table pz_yjd_pzh alter column lastmodifieddate set default =DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')`  ) 
    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select * from pz_yjd_pzh where billtype='交办'` ) 


    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join (
        select a.* from pz_yjd a 
        left join ( select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) b 
        on b.lastmodifieddate=a.lastmodifieddate and a.corpid =b.corpid
    ) b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a22a7a993295696042f4a8
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.26 09:07:25.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

// runSQL('', `alter table pz_yjd_pzh alter column lastmodifieddate set default =DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')`  ) 
    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select * from pz_yjd_pzh where billtype='交办'` ) 


    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join (
        select a.* from pz_yjd a 
        left join ( select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) b 
        on b.lastmodifieddate=a.lastmodifieddate and a.corpid =b.corpid
    ) b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a22a7a993295696042f4ae
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.26 09:07:28.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

// runSQL('', `alter table pz_yjd_pzh alter column lastmodifieddate set default =DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')`  ) 
    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    // return getListFromSQL2( '',  ` select * from pz_yjd_pzh where billtype='交办'` ) 


    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join (
        select a.* from pz_yjd a 
        left join ( select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) b 
        on b.lastmodifieddate=a.lastmodifieddate and a.corpid =b.corpid
    ) b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a22a7a993295696042f4ba
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.26 09:08:48.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

// runSQL('', `alter table pz_yjd_pzh alter column lastmodifieddate set default =DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')`  ) 
    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from pz_yjd_pzh  a1 left join pz_yjd b1 on a1.gguid=b1.gguid where  billtype='交办'  group by corpid_ny_pzh   ` ) 


    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join (
        select a.* from pz_yjd a 
        left join ( select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) b 
        on b.lastmodifieddate=a.lastmodifieddate and a.corpid =b.corpid
    ) b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a22a7a993295696042f4c0
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.26 09:09:02.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

// runSQL('', `alter table pz_yjd_pzh alter column lastmodifieddate set default =DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')`  ) 
    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from pz_yjd_pzh  a1 left join pz_yjd b1 on a1.gguid=b1.gguid where  b.billtype='交办'  group by corpid_ny_pzh   ` ) 


    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join (
        select a.* from pz_yjd a 
        left join ( select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) b 
        on b.lastmodifieddate=a.lastmodifieddate and a.corpid =b.corpid
    ) b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a22a7a993295696042f4c6
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.26 09:09:12.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

// runSQL('', `alter table pz_yjd_pzh alter column lastmodifieddate set default =DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')`  ) 
    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from pz_yjd_pzh  a1 left join pz_yjd b1 on a1.gguid=b1.gguid where  a1.billtype='交办'  group by corpid_ny_pzh   ` ) 


    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join (
        select a.* from pz_yjd a 
        left join ( select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) b 
        on b.lastmodifieddate=a.lastmodifieddate and a.corpid =b.corpid
    ) b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a22a7a993295696042f4cc
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.26 09:11:28.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

// runSQL('', `alter table pz_yjd_pzh alter column lastmodifieddate set default =DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')`  ) 
    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select * from (select b1.lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from pz_yjd_pzh  a1 left join pz_yjd b1 on a1.gguid=b1.gguid where  a1.billtype='交办') a group by corpid_ny_pzh   ` ) 


    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join (
        select a.* from pz_yjd a 
        left join ( select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) b 
        on b.lastmodifieddate=a.lastmodifieddate and a.corpid =b.corpid
    ) b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a22a7a993295696042f4d2
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.26 09:12:06.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

// runSQL('', `alter table pz_yjd_pzh alter column lastmodifieddate set default =DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')`  ) 
    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select b1.lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from pz_yjd_pzh  a1 left join pz_yjd b1 on a1.gguid=b1.gguid where  a1.billtype='交办'   ` ) 
    
    return getListFromSQL2( '',  ` select * from (select b1.lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from pz_yjd_pzh  a1 left join pz_yjd b1 on a1.gguid=b1.gguid where  a1.billtype='交办') a group by corpid_ny_pzh   ` ) 


    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join (
        select a.* from pz_yjd a 
        left join ( select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) b 
        on b.lastmodifieddate=a.lastmodifieddate and a.corpid =b.corpid
    ) b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


id: 66a2f859993295696042f617
scriptid: 650666139932de686bb62112
tablename: app_script
clientip: 122.235.158.135
username: sa
createdate: 2024.07.26 09:14:21.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{

// runSQL('', `alter table pz_yjd_pzh alter column lastmodifieddate set default =DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')`  ) 
    // return getListFromSQL2( '',  ` SELECT 
    // max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT(a.ny, a.pzh) AS ny_pzh,
    // case 
    //     when a.billtype ='交办' and b.flow_instance_state='0' then '交办中'
    //     when a.billtype ='交办' and b.flow_instance_state='1' and a.billtype ='交回' and b.flow_instance_state='0' then '交办没有交回' 
    // else end as jbzt
    // from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid  where a.billtype='交办'
    // group by ny_pzh` ) 
    
    return getListFromSQL2( '',  ` select b1.lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from pz_yjd_pzh  a1 left join pz_yjd b1 on a1.gguid=b1.gguid where  a1.billtype='交办' and b.corpid is not null   ` ) 
    
    return getListFromSQL2( '',  ` select * from (select b1.lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from pz_yjd_pzh  a1 left join pz_yjd b1 on a1.gguid=b1.gguid where  a1.billtype='交办') a group by corpid_ny_pzh   ` ) 


    
    return getListFromSQL2( '',  ` SELECT 
    max(b.corpid) as corpid,  max(a.ny) as ny, max(a.pzh) as pzh,   CONCAT( CONCAT(b.corpid, a.ny), a.pzh) AS corpid_ny_pzh, max(b.flow_instance_state) as flow_instance_state
    from (select * from pz_yjd_pzh where billtype='交办') a 
    left join (
        select a.* from pz_yjd a 
        left join ( select max(b1.lastmodifieddate) as lastmodifieddate, b1.corpid,  CONCAT( CONCAT(b1.corpid, a1.ny), a1.pzh) AS corpid_ny_pzh 
        from (select * from pz_yjd_pzh where billtype='交办')  a1 left join pz_yjd b1 on a1.gguid=b1.gguid   group by corpid_ny_pzh ) b 
        on b.lastmodifieddate=a.lastmodifieddate and a.corpid =b.corpid
    ) b on a.gguid=b.gguid   
    group by corpid_ny_pzh` ) 
    
    

    return false
    
   var t='2023-02-23 ';
var s= t.match(  /20[0-9]{2}-[0-9]{2}-[0-9]{2}/g);
return s;   
    
    return OCR ( { src:'fileServer?bucketName=电子凭证&objectName=dzpz_imgpool/2023/09/17/650665939932db10f02cebaf.jpg&fileName=p4.jpg&serverIndex=2&action=view' ,
             left:'50%' , top:'20%' ,height:'20%' ,width:'50%'} );


}


