# app_script_history

id: 65275bfe993258e5b47470f8
scriptid: 60c4bd735db2478f9c5a111c
tablename: app_template
clientip: 39.170.92.207
username: sa
createdate: 2023.10.12 10:45:30.000
script:
var pzh_prefix;
var pzh_length;

var fullScreenDiv = null;



function formOpen() {
    book.showTabOnWhere = 'none';
    //加载帐套信息及年月
    var corpid = book.sheet0.cells("corpid").getValueString();
    runTask("当前记帐期", { corpid: corpid }, function (ym) {
        if (ym == null || ym == 'null') return;
        //得到年月后，获取凭证号相关设置
        pzh_len = getPZHLen(corpid);

        book.sheet0.cells("ym").setValue(ym);

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);


    });

    book.sheet2.getBrick('FJ').selectionMode = 'multi'; //图片设置成多选模式


    // 追加一些CSS类 ，用于凭证号标记
    $(document.body).append(`<style>
                        .pzh {position:absolute;left:0;bottom:0px; 
                                height:24px; line-height:24px;width:100%; 
                                background-color:#40af40a0; 
                                color:white;font-weight:bold;font-size:12px;text-align:center;}
                        .delete_pzh { position:absolute; right:0; width:40px; height:14px; top:0; text-align:right; 
                                    vertical-align:top; font-size:12px; color:gray;padding-right:5px;}      
                        .delete_pzh:hover { color:white;}      
                          
                        </style>
                    `);


}

function cb_check_onClick() {
    smartRetrieve(book.sheet0, "pzh_check", true, false, function () { //检索完后回调
        if ($pzh_check_ds.rowCount == 0) {
            toastr.success("凭证号检测通过");

        } else {
            book.sheet3.popup('fa fa-cog', '缺失的凭证', 250, 350, true, true, {});
        }
    });
}


/**
 * 多行结果集当前焦点行发生变化
 * @param dsname  结果集名称
 * @param row  行号
 */
//@comment (group=单元格事件,caption=单元格行焦点发生变化)
function currentBindRowChanged(dsname, row) {
    if (dsname == 'dzpz_pz') {
        //重新加载凭证图片列表

        let id = $dzpz_pz_ds.getString(row, "id");
        let pzh = $dzpz_pz_ds.getString(row, "pzh");
        loadPZ(pzh, id);

    }
}

function viewPDF(id) {
    var url = get_PZ_PDF_URL(id);
    openWindow(url);
}

/**
 * 单元格的值发生了改变
 * @param sheet  所在的工作表
 * @param cell  单元格对象
 * @param oldValue  原先的值
 * @param newValue 变化后的值
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChanged(sheet, cell, oldValue, newValue, innerRow) {

    //如果是绑定了数据库的，强烈不建议使用本事件，换用结果集变化事件 itemChanged

    //通过别名来判断
    if (cell.alias == 'ym') {
        var corpid = book.sheet0.cells("corpid").getValueString();
        var ym = book.sheet0.cells("ym").getValue();

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);
    }




}

function loadPZ(pzh, id) {
    
    let data = getPZFJ(id); //得到凭证的所有图片
    let FJ = book.sheet2.getBrick('FJ');
    FJ.buildGridly(data, function () {
        let shortPZH = pzh;//.substring(pzh_prefix.length);
        //加载图片完成后， 如果是凭证，那么加上凭证号信息
        for (let i = 0; i < data.length; i++) {
            if (data[i].groupname == '凭证') {
                setPZH(data[i].id, shortPZH, false);
            }
        }




    });
    g_selectedAll = false; //加载一个凭证的图片后 ，默认是不全选中的
    book.sheet2.yOffset = 0; //垂直卷滚条归位
}


//@comment (group=凭证号,caption=设置图片的凭证号,needRightControl=false)
function setPZH(id, pzh, needDeleteButton) {
    if (needDeleteButton == undefined) needDeleteButton = true
    find_pzh(id, true, needDeleteButton).find('.no').text(pzh);
}

//@comment (group=凭证号,caption=查找或创建凭证号标记对象,needRightControl=false)
function find_pzh(id, create_if_not_exists, needDeleteButton) {

    if (needDeleteButton == undefined) needDeleteButton = true;

    var d = $('#' + id);
    if (!d) {
        $.alert(id + "不存在");
        return null;
    }

    var ret = d.find('.pzh');
    if (ret.length == 0) {
        if (create_if_not_exists) //如果需要创建，则创建它
        {
            d.append(`<div class="pzh" >
                        <div class="no"></div>
                        <div class="delete_pzh"  ${needDeleteButton ? "" : " style='display:none' "} ><i class="fa fa-close" onclick="removePZH('${id}');  event.preventDefault(); event.stopPropagation();"> </i></div>
                      </div>`);
        }
        ret = d.find('.pzh');
    }
    return ret;

}



/**
 * 单元格单击事件
 * @param sheet
 * @param cell
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行被点击
 * @param event 事件对象
 */
//@comment (group=单元格事件,caption=单元格点击)
function cellOnClick(sheet, cell, innerRow, event) {

    //通过别名来判断
    if (cell.alias == 'XXX') {

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'dzpz_pz') {
        if (bind.DBCol == 'c_sh1') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") != 0) return; //已审核，不要再审核
            do_sh1(innerRow, function () {
                if (innerRow < $dzpz_pz_ds.rowCount - 1) {
                    book.getDataSource('dzpz_pz').currentBindRow = innerRow + 1 ;
                }
            });
        }
        if (bind.DBCol == 'c_sh2') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") == 0) return; //没有审核，不需要取消审核
            do_sh2(innerRow);
        }
    }

}

function do_sh1(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    let pzh = $dzpz_pz_ds.getString(innerRow, "pzh");

    do_sh(id, true, function (ret)  //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", ret.verifierid);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", ret.verifiername);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", ret.verifieddate);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "校对成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "取消校对");

        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}

function do_sh2(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    do_sh(id, false, function (ret) //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", null);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", null);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", null);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "取消成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "校对");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "");


        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}



//@comment (group=工具函数,caption=全选或取消全选)
function seletOrUnSelectAll() {
    //让selection单元格失去编辑焦点，不然再点击，它不会触发单元格的点击事件，因为此时点击的编辑框对象，不会触发单元格的点击
    book.sheet1.View.forceCurrentEditControlGiveUpFocus();

    var v = book.sheet1.cells('selection').getValueInt();

    book.sheet1.paintPermit = false;
    $dzpz_pz_ds.setValueWithTrigger = false;
    for (var i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        $dzpz_pz_ds.setValue(i, "selected", v);
    }
    $dzpz_pz_ds.setValueWithTrigger = true;
    book.sheet1.paintPermit = true;
}


function cb_verify_onClick() {
    $confirm('', '确信要对选中的凭证做审核确认吗?', function () {
        let rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在审核确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在校对确认 " + i);
                do_sh1(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("校对完成");
        });

    });
}



function cb_unverify_onClick() {

    $confirm('', '确信要对选中的凭证做取消校对吗?', function () {
        var rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在取消确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在取消确认" + i);
                do_sh2(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("取消确认完成");
        });

    });


}


function cb_package_onClick() {

    let ids = [];
    for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
        ids.push($dzpz_pz_ds.getString(i, "id"));
    }

    if (ids.length == 0) {
        toastr.info("至少选中一张凭证");
        return;
    }

    $confirm('', '确信要将选中的凭证打包下载吗?', function () {
        showInfoPane("*正在压缩打包...");
        runTask("打包下载", { fileName: formatDate(newDate(), "yyyyMMddHHmm") + ".zip", ids: ids },
            function (ret) {
                ret = JSON.parse(ret);
                hideInfoPane();
                if (ret.success) {
                    openWindow(ret.url);
                } else {
                    toastr.error(ret.message);
                }
            });

    });
}

function isVerified() {
    var row = book.getDataSource('dzpz_pz').currentBindRow;
    var verifiername = $dzpz_pz_ds.getString(row, "verifiername");

    if (verifiername != '') {
        toastr.error("已经校对的凭证不允许执行此操作");
        return true;
    }
    return false;
}


/**
 * 图片控件初始化完成
 * @param sheet   所在Sheet
 * @param config  图片控件的名称
 *@param data  该图片的详细信息
 *
 */
//@comment (group=图片控件,caption=图片控件初始化完成)
function imageGridlyInited(sheet, name, data) {


    if (name == "FJ") {
        //图片都初始化后， 定制右上角的工具栏，最多可加5个工具按 钮
        let brick = sheet.getBrick(name);

        brick.addToolButton(1  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-repeat",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '90', function () { hideInfoPane(); });

            }
        );


        brick.addToolButton(2  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-eye",   // 字符图标
            "浏览大图",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                brick.popupShow(id);

            }
        );


        brick.addToolButton(3  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-rotate-left",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '270', function () { hideInfoPane(); });

            }
        );



    }
}


function rotateImg(sheet, id, degree, callback) {



    let brick = sheet.getBrick('FJ');
    setTimeout(function () {
        //toastr.info(id);  // id 是当前操作的图片对应数据的ID

        do_imageRotate(id, degree, function (ret) {


            if (ret.success) {

                g_turningCount++;
                showInfoPane('*正在旋转图片' + g_turningCount + "/" + g_turnNeedCount + ' ...');


                //把数据中的图片替换，
                for (let i = 0; i < brick.data.length; i++) {
                    if (brick.data[i].id == id) {
                        //属性从新的属性中替换 
                        for (let prop in brick.data[i]) {
                            brick.data[i][prop] = ret.data[prop];
                        }
                        break;
                    }
                }
                //把缩略图的图片地址替换 ， 

                let img = $('#' + id).find('.image');
                img.attr("src", ret.data.url_thumbnail);
                img.attr('largeimage', ret.data.url_img);
                //把大图预览的地址替换掉
                //book.sheet0.cells("imgPreview").setValue(ret.data.url_img);

            }
            if (callback) callback();



        });
    }, 100);

}


/**
 * 图片控件中的图片控件顺序发生变化
 * @param sheet   所在Sheet
 * @param name  图片控件的名称
 *@param  ids  当前顺序下的图片的ID数组
 *
 *
 *
 */
//@comment (group=图片控件,caption=图片顺序被改变)
function imageOrderChanged(sheet, name, ids) {

    if (isVerified()) return;  //校对过的不允许再调整顺序

    reOrderImage(ids, function (ret) { }); //放一个空的回调函数让它异步执行，不卡界面

}


var g_selectedAll = false;
function cb_selectallimg_onClick() { g_selectedAll = !g_selectedAll; doSelect(g_selectedAll); }


function doSelect(b) {
    var imgPool = book.sheet2.getBrick('FJ');
    if (b) {
        imgPool.selectAll();
    } else {
        imgPool.unSelectAll();
    }
}


function cb_turnLeft_onClick() {
    turnSelection('270');

}

function cb_turnRight_onClick() {

    turnSelection('90');
}

var g_turningCount = 0;
var g_turnedCount = 0;

function turnSelection(degree) {

    if (isVerified()) return;  //校对过的不允许再旋转

    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    // 当前选中的
    var selection = imgPool.getSelectedImageList();
    if (selection.length == 0) {
        toastr.error("至少选中一张图片");
        return;
    }


    $confirm("提示", "确信要对选中的" + selection.length + "张图片做旋转吗?", function () {

        g_turningCount = 0;
        g_turnedCount = 0;
        g_turnNeedCount = selection.length;
        /*
                setTimeout(function () {
                    for (var i = 0; i < selection.length; i++) {
                        rotateImg(sheet, selection[i].id, degree, i * 1000);
                    }
                }, 10);
                */

        asyncPool(4, selection, function (item, array) {
            return new Promise(function (resolve, reject) {

                console.dir(item);
                rotateImg(sheet, item.id, degree,
                    function () { //注意，在旋转完成后，再设置resolve 表示本任务已完成，而不是直接就resolve ,不然最后的 then 执行时机不对，这么处理，就会在全部旋转完成后，再执行then中的脚本，而不是旋转任务全部发起后就执行 then 
                        resolve(item)
                    });

            });
        }).then(function () {

            setTimeout(function () {

                hideInfoPane();
                toastr.info("旋转完成");
            }, 500);
        });

    });

}




function test1() {


    asyncPool(3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (item, array) {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                console.info(item + "   " + new Date());
                resolve(item)
            }, 1000);

        });
    }).then(function () {
        console.info("over");
    });

}


id: 6536a306993258e5b47474cb
scriptid: 60c4bd735db2478f9c5a111c
tablename: app_template
clientip: 39.170.92.207
username: sa
createdate: 2023.10.24 10:44:34.000
script:
var pzh_prefix;
var pzh_length;

var fullScreenDiv = null;



function formOpen() {
    book.showTabOnWhere = 'none';
    //加载帐套信息及年月
    var corpid = book.sheet0.cells("corpid").getValueString();
    runTask("当前记帐期", { corpid: corpid }, function (ym) {
        if (ym == null || ym == 'null') return;
        //得到年月后，获取凭证号相关设置
        pzh_len = getPZHLen(corpid);

        book.sheet0.cells("ym").setValue(ym);

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);


    });

    book.sheet2.getBrick('FJ').selectionMode = 'multi'; //图片设置成多选模式


    // 追加一些CSS类 ，用于凭证号标记
    $(document.body).append(`<style>
                        .pzh {position:absolute;left:0;bottom:0px; 
                                height:24px; line-height:24px;width:100%; 
                                background-color:#40af40a0; 
                                color:white;font-weight:bold;font-size:12px;text-align:center;}
                        .delete_pzh { position:absolute; right:0; width:40px; height:14px; top:0; text-align:right; 
                                    vertical-align:top; font-size:12px; color:gray;padding-right:5px;}      
                        .delete_pzh:hover { color:white;}      
                          
                        </style>
                    `);


}

function cb_check_onClick() {
    smartRetrieve(book.sheet0, "pzh_check", true, false, function () { //检索完后回调
        if ($pzh_check_ds.rowCount == 0) {
            toastr.success("凭证号检测通过");

        } else {
            book.sheet3.popup('fa fa-cog', '缺失的凭证', 250, 350, true, true, {});
        }
    });
}


/**
 * 多行结果集当前焦点行发生变化
 * @param dsname  结果集名称
 * @param row  行号
 */
//@comment (group=单元格事件,caption=单元格行焦点发生变化)
function currentBindRowChanged(dsname, row) {
    if (dsname == 'dzpz_pz') {
        //重新加载凭证图片列表

        let id = $dzpz_pz_ds.getString(row, "id");
        let pzh = $dzpz_pz_ds.getString(row, "pzh");
        loadPZ(pzh, id);

    }
}

function viewPDF(id) {
    var url = get_PZ_PDF_URL(id);
    openWindow(url);
}

/**
 * 单元格的值发生了改变
 * @param sheet  所在的工作表
 * @param cell  单元格对象
 * @param oldValue  原先的值
 * @param newValue 变化后的值
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChanged(sheet, cell, oldValue, newValue, innerRow) {

    //如果是绑定了数据库的，强烈不建议使用本事件，换用结果集变化事件 itemChanged

    //通过别名来判断
    if (cell.alias == 'ym') {
        var corpid = book.sheet0.cells("corpid").getValueString();
        var ym = book.sheet0.cells("ym").getValue();

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);
    }




}

function loadPZ(pzh, id) {

    let data = getPZFJ(id); //得到凭证的所有图片
    let FJ = book.sheet2.getBrick('FJ');
    FJ.buildGridly(data, function () {
        let shortPZH = pzh;//.substring(pzh_prefix.length);
        //加载图片完成后， 如果是凭证，那么加上凭证号信息
        for (let i = 0; i < data.length; i++) {
            if (data[i].groupname == '凭证') {
                setPZH(data[i].id, shortPZH, false);
            }
        }




    });
    g_selectedAll = false; //加载一个凭证的图片后 ，默认是不全选中的
    book.sheet2.yOffset = 0; //垂直卷滚条归位
}


//@comment (group=凭证号,caption=设置图片的凭证号,needRightControl=false)
function setPZH(id, pzh, needDeleteButton) {
    if (needDeleteButton == undefined) needDeleteButton = true
    find_pzh(id, true, needDeleteButton).find('.no').text(pzh);
}

//@comment (group=凭证号,caption=查找或创建凭证号标记对象,needRightControl=false)
function find_pzh(id, create_if_not_exists, needDeleteButton) {

    if (needDeleteButton == undefined) needDeleteButton = true;

    var d = $('#' + id);
    if (!d) {
        $.alert(id + "不存在");
        return null;
    }

    var ret = d.find('.pzh');
    if (ret.length == 0) {
        if (create_if_not_exists) //如果需要创建，则创建它
        {
            d.append(`<div class="pzh" >
                        <div class="no"></div>
                        <div class="delete_pzh"  ${needDeleteButton ? "" : " style='display:none' "} ><i class="fa fa-close" onclick="removePZH('${id}');  event.preventDefault(); event.stopPropagation();"> </i></div>
                      </div>`);
        }
        ret = d.find('.pzh');
    }
    return ret;

}



/**
 * 单元格单击事件
 * @param sheet
 * @param cell
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行被点击
 * @param event 事件对象
 */
//@comment (group=单元格事件,caption=单元格点击)
function cellOnClick(sheet, cell, innerRow, event) {

    //通过别名来判断
    if (cell.alias == 'XXX') {

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'dzpz_pz') {
        if (bind.DBCol == 'c_sh1') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") != 0) return; //已审核，不要再审核
            do_sh1(innerRow, function () {
                if (innerRow < $dzpz_pz_ds.rowCount - 1) {
                    book.getDataSource('dzpz_pz').currentBindRow = innerRow + 1;
                }
            });
        }
        if (bind.DBCol == 'c_sh2') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") == 0) return; //没有审核，不需要取消审核
            do_sh2(innerRow);
        }
    }

}

function do_sh1(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    let pzh = $dzpz_pz_ds.getString(innerRow, "pzh");

    do_sh(id, true, function (ret)  //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", ret.verifierid);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", ret.verifiername);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", ret.verifieddate);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "校对成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "取消校对");

        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}

function do_sh2(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    do_sh(id, false, function (ret) //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", null);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", null);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", null);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "取消成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "校对");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "");


        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}



//@comment (group=工具函数,caption=全选或取消全选)
function seletOrUnSelectAll() {
    //让selection单元格失去编辑焦点，不然再点击，它不会触发单元格的点击事件，因为此时点击的编辑框对象，不会触发单元格的点击
    book.sheet1.View.forceCurrentEditControlGiveUpFocus();

    var v = book.sheet1.cells('selection').getValueInt();

    book.sheet1.paintPermit = false;
    $dzpz_pz_ds.setValueWithTrigger = false;
    for (var i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        $dzpz_pz_ds.setValue(i, "selected", v);
    }
    $dzpz_pz_ds.setValueWithTrigger = true;
    book.sheet1.paintPermit = true;
}


function cb_verify_onClick() {
    $confirm('', '确信要对选中的凭证做审核确认吗?', function () {
        let rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在审核确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在校对确认 " + i);
                do_sh1(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("校对完成");
        });

    });
}



function cb_unverify_onClick() {

    $confirm('', '确信要对选中的凭证做取消校对吗?', function () {
        var rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在取消确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在取消确认" + i);
                do_sh2(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("取消确认完成");
        });

    });


}


function cb_package_onClick() {

    let ids = [];
    for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
        ids.push($dzpz_pz_ds.getString(i, "id"));
    }

    if (ids.length == 0) {
        toastr.info("至少选中一张凭证");
        return;
    }

    $confirm('', '确信要将选中的凭证打包下载吗?', function () {
        showInfoPane("*正在压缩打包...");
        runTask("打包下载", { fileName: formatDate(newDate(), "yyyyMMddHHmm") + ".zip", ids: ids },
            function (ret) {
                ret = JSON.parse(ret);
                hideInfoPane();
                if (ret.success) {
                    openWindow(ret.url);
                } else {
                    toastr.error(ret.message);
                }
            });

    });
}

function isVerified() {
    var row = book.getDataSource('dzpz_pz').currentBindRow;
    var verifiername = $dzpz_pz_ds.getString(row, "verifiername");

    if (verifiername != '') {
        toastr.error("已经校对的凭证不允许执行此操作");
        return true;
    }
    return false;
}


/**
 * 图片控件初始化完成
 * @param sheet   所在Sheet
 * @param config  图片控件的名称
 *@param data  该图片的详细信息
 *
 */
//@comment (group=图片控件,caption=图片控件初始化完成)
function imageGridlyInited(sheet, name, data) {


    if (name == "FJ") {
        //图片都初始化后， 定制右上角的工具栏，最多可加5个工具按 钮
        let brick = sheet.getBrick(name);

        brick.addToolButton(1  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-repeat",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '90', function () { hideInfoPane(); });

            }
        );


        brick.addToolButton(2  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-eye",   // 字符图标
            "浏览大图",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                brick.popupShow(id);

            }
        );


        brick.addToolButton(3  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-rotate-left",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '270', function () { hideInfoPane(); });

            }
        );



    }
}


function rotateImg(sheet, id, degree, callback) {



    let brick = sheet.getBrick('FJ');
    setTimeout(function () {
        //toastr.info(id);  // id 是当前操作的图片对应数据的ID

        do_imageRotate(id, degree, function (ret) {


            if (ret.success) {

                g_turningCount++;
                showInfoPane('*正在旋转图片' + g_turningCount + "/" + g_turnNeedCount + ' ...');


                //把数据中的图片替换，
                for (let i = 0; i < brick.data.length; i++) {
                    if (brick.data[i].id == id) {
                        //属性从新的属性中替换 
                        for (let prop in brick.data[i]) {
                            brick.data[i][prop] = ret.data[prop];
                        }
                        break;
                    }
                }
                //把缩略图的图片地址替换 ， 

                let img = $('#' + id).find('.image');
                img.attr("src", ret.data.url_thumbnail);
                img.attr('largeimage', ret.data.url_img);
                //把大图预览的地址替换掉
                //book.sheet0.cells("imgPreview").setValue(ret.data.url_img);

            }
            if (callback) callback();



        });
    }, 100);

}


/**
 * 图片控件中的图片控件顺序发生变化
 * @param sheet   所在Sheet
 * @param name  图片控件的名称
 *@param  ids  当前顺序下的图片的ID数组
 *
 *
 *
 */
//@comment (group=图片控件,caption=图片顺序被改变)
function imageOrderChanged(sheet, name, ids) {

    if (isVerified()) return;  //校对过的不允许再调整顺序

    reOrderImage(ids, function (ret) { }); //放一个空的回调函数让它异步执行，不卡界面

}


var g_selectedAll = false;
function cb_selectallimg_onClick() { g_selectedAll = !g_selectedAll; doSelect(g_selectedAll); }


function doSelect(b) {
    var imgPool = book.sheet2.getBrick('FJ');
    if (b) {
        imgPool.selectAll();
    } else {
        imgPool.unSelectAll();
    }
}


function cb_turnLeft_onClick() {
    turnSelection('270');

}

function cb_turnRight_onClick() {

    turnSelection('90');
}

var g_turningCount = 0;
var g_turnedCount = 0;

function turnSelection(degree) {

    if (isVerified()) return;  //校对过的不允许再旋转

    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    // 当前选中的
    var selection = imgPool.getSelectedImageList();
    if (selection.length == 0) {
        toastr.error("至少选中一张图片");
        return;
    }


    $confirm("提示", "确信要对选中的" + selection.length + "张图片做旋转吗?", function () {

        g_turningCount = 0;
        g_turnedCount = 0;
        g_turnNeedCount = selection.length;
        /*
                setTimeout(function () {
                    for (var i = 0; i < selection.length; i++) {
                        rotateImg(sheet, selection[i].id, degree, i * 1000);
                    }
                }, 10);
                */

        asyncPool(4, selection, function (item, array) {
            return new Promise(function (resolve, reject) {

                console.dir(item);
                rotateImg(sheet, item.id, degree,
                    function () { //注意，在旋转完成后，再设置resolve 表示本任务已完成，而不是直接就resolve ,不然最后的 then 执行时机不对，这么处理，就会在全部旋转完成后，再执行then中的脚本，而不是旋转任务全部发起后就执行 then 
                        resolve(item)
                    });

            });
        }).then(function () {

            setTimeout(function () {

                hideInfoPane();
                toastr.info("旋转完成");
            }, 500);
        });

    });

}




function test1() {


    asyncPool(3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (item, array) {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                console.info(item + "   " + new Date());
                resolve(item)
            }, 1000);

        });
    }).then(function () {
        console.info("over");
    });

}



function ocrTest() {
    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    let imgs = imgPool.getCurrentSortedImageList();//得到当前排序后的图片清单
    let one = imgs[0];

    runTask("pzh-ocr", { src: one.url_img, left: '35%', top: '8%', height: '8%', width: '50%' }, function (text) {
        toastr.info(text);
    });

}


id: 65486120993213e6a7b24eb5
scriptid: 60c4bd735db2478f9c5a111c
tablename: app_template
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 13:42:13.000
script:
var pzh_prefix;
var pzh_length;

var fullScreenDiv = null;



function formOpen() {
    book.showTabOnWhere = 'none';
    //加载帐套信息及年月
    var corpid = book.sheet0.cells("corpid").getValueString();
    runTask("当前记帐期", { corpid: corpid }, function (ym) {
        if (ym == null || ym == 'null') return;
        //得到年月后，获取凭证号相关设置
        pzh_len = getPZHLen(corpid);

        book.sheet0.cells("ym").setValue(ym);

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);


    });

    book.sheet2.getBrick('FJ').selectionMode = 'multi'; //图片设置成多选模式


    // 追加一些CSS类 ，用于凭证号标记
    $(document.body).append(`<style>
                        .pzh {position:absolute;left:0;bottom:0px; 
                                height:24px; line-height:24px;width:100%; 
                                background-color:#40af40a0; 
                                color:white;font-weight:bold;font-size:12px;text-align:center;}
                        .delete_pzh { position:absolute; right:0; width:40px; height:14px; top:0; text-align:right; 
                                    vertical-align:top; font-size:12px; color:gray;padding-right:5px;}      
                        .delete_pzh:hover { color:white;}      
                          
                        </style>
                    `);


}

function cb_check_onClick() {
    smartRetrieve(book.sheet0, "pzh_check", true, false, function () { //检索完后回调
        if ($pzh_check_ds.rowCount == 0) {
            toastr.success("凭证号检测通过");

        } else {
            book.sheet3.popup('fa fa-cog', '缺失的凭证', 250, 350, true, true, {});
        }
    });
}


/**
 * 多行结果集当前焦点行发生变化
 * @param dsname  结果集名称
 * @param row  行号
 */
//@comment (group=单元格事件,caption=单元格行焦点发生变化)
function currentBindRowChanged(dsname, row) {
    if (dsname == 'dzpz_pz') {
        //重新加载凭证图片列表

        let id = $dzpz_pz_ds.getString(row, "id");
        let pzh = $dzpz_pz_ds.getString(row, "pzh");
        loadPZ(pzh, id);

    }
}

function viewPDF(id) {
    var url = get_PZ_PDF_URL(id);
    openWindow(url);
}

/**
 * 单元格的值发生了改变
 * @param sheet  所在的工作表
 * @param cell  单元格对象
 * @param oldValue  原先的值
 * @param newValue 变化后的值
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChanged(sheet, cell, oldValue, newValue, innerRow) {

    //如果是绑定了数据库的，强烈不建议使用本事件，换用结果集变化事件 itemChanged

    //通过别名来判断
    if (cell.alias == 'ym') {
        var corpid = book.sheet0.cells("corpid").getValueString();
        var ym = book.sheet0.cells("ym").getValue();

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);
    }




}

function loadPZ(pzh, id) {

    let data = getPZFJ(id); //得到凭证的所有图片
    let FJ = book.sheet2.getBrick('FJ');
    FJ.buildGridly(data, function () {
        let shortPZH = pzh;//.substring(pzh_prefix.length);
        //加载图片完成后， 如果是凭证，那么加上凭证号信息
        for (let i = 0; i < data.length; i++) {
            if (data[i].groupname == '凭证') {
                setPZH(data[i].id, shortPZH, false);
            }
        }




    });
    g_selectedAll = false; //加载一个凭证的图片后 ，默认是不全选中的
    book.sheet2.yOffset = 0; //垂直卷滚条归位
}


//@comment (group=凭证号,caption=设置图片的凭证号,needRightControl=false)
function setPZH(id, pzh, needDeleteButton) {
    if (needDeleteButton == undefined) needDeleteButton = true
    find_pzh(id, true, needDeleteButton).find('.no').text(pzh);
}

//@comment (group=凭证号,caption=查找或创建凭证号标记对象,needRightControl=false)
function find_pzh(id, create_if_not_exists, needDeleteButton) {

    if (needDeleteButton == undefined) needDeleteButton = true;

    var d = $('#' + id);
    if (!d) {
        $.alert(id + "不存在");
        return null;
    }

    var ret = d.find('.pzh');
    if (ret.length == 0) {
        if (create_if_not_exists) //如果需要创建，则创建它
        {
            d.append(`<div class="pzh" >
                        <div class="no"></div>
                        <div class="delete_pzh"  ${needDeleteButton ? "" : " style='display:none' "} ><i class="fa fa-close" onclick="removePZH('${id}');  event.preventDefault(); event.stopPropagation();"> </i></div>
                      </div>`);
        }
        ret = d.find('.pzh');
    }
    return ret;

}



/**
 * 单元格单击事件
 * @param sheet
 * @param cell
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行被点击
 * @param event 事件对象
 */
//@comment (group=单元格事件,caption=单元格点击)
function cellOnClick(sheet, cell, innerRow, event) {

    //通过别名来判断
    if (cell.alias == 'XXX') {

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'dzpz_pz') {
        if (bind.DBCol == 'c_sh1') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") != 0) return; //已审核，不要再审核
            do_sh1(innerRow, function () {
                if (innerRow < $dzpz_pz_ds.rowCount - 1) {
                    book.getDataSource('dzpz_pz').currentBindRow = innerRow + 1;
                }
            });
        }
        if (bind.DBCol == 'c_sh2') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") == 0) return; //没有审核，不需要取消审核
            do_sh2(innerRow);
        }
    }

}

function do_sh1(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    let pzh = $dzpz_pz_ds.getString(innerRow, "pzh");

    do_sh(id, true, function (ret)  //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", ret.verifierid);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", ret.verifiername);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", ret.verifieddate);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "校对成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "取消校对");

        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}

function do_sh2(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    do_sh(id, false, function (ret) //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", null);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", null);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", null);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "取消成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "校对");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "");


        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}



//@comment (group=工具函数,caption=全选或取消全选)
function seletOrUnSelectAll() {
    //让selection单元格失去编辑焦点，不然再点击，它不会触发单元格的点击事件，因为此时点击的编辑框对象，不会触发单元格的点击
    book.sheet1.View.forceCurrentEditControlGiveUpFocus();

    var v = book.sheet1.cells('selection').getValueInt();

    book.sheet1.paintPermit = false;
    $dzpz_pz_ds.setValueWithTrigger = false;
    for (var i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        $dzpz_pz_ds.setValue(i, "selected", v);
    }
    $dzpz_pz_ds.setValueWithTrigger = true;
    book.sheet1.paintPermit = true;
}


function cb_verify_onClick() {
    $confirm('', '确信要对选中的凭证做审核确认吗?', function () {
        let rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在审核确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在校对确认 " + i);
                do_sh1(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("校对完成");
        });

    });
}



function cb_unverify_onClick() {

    $confirm('', '确信要对选中的凭证做取消校对吗?', function () {
        var rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在取消确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在取消确认" + i);
                do_sh2(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("取消确认完成");
        });

    });


}


function cb_package_onClick() {

    let ids = [];
    for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
        ids.push($dzpz_pz_ds.getString(i, "id"));
    }

    if (ids.length == 0) {
        toastr.info("至少选中一张凭证");
        return;
    }

    $confirm('', '确信要将选中的凭证打包下载吗?', function () {
        showInfoPane("*正在压缩打包...");
        runTask("打包下载", { fileName: formatDate(newDate(), "yyyyMMddHHmm") + ".zip", ids: ids },
            function (ret) {
                ret = JSON.parse(ret);
                hideInfoPane();
                if (ret.success) {
                    openWindow(ret.url);
                } else {
                    toastr.error(ret.message);
                }
            });

    });
}

function isVerified() {
    var row = book.getDataSource('dzpz_pz').currentBindRow;
    var verifiername = $dzpz_pz_ds.getString(row, "verifiername");

    if (verifiername != '') {
        toastr.error("已经校对的凭证不允许执行此操作");
        return true;
    }
    return false;
}


/**
 * 图片控件初始化完成
 * @param sheet   所在Sheet
 * @param config  图片控件的名称
 *@param data  该图片的详细信息
 *
 */
//@comment (group=图片控件,caption=图片控件初始化完成)
function imageGridlyInited(sheet, name, data) {


    if (name == "FJ") {
        //图片都初始化后， 定制右上角的工具栏，最多可加5个工具按 钮
        let brick = sheet.getBrick(name);

        brick.addToolButton(1  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-repeat",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '90', function () { hideInfoPane(); });

            }
        );


        brick.addToolButton(2  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-eye",   // 字符图标
            "浏览大图",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                brick.popupShow(id);

            }
        );


          brick.addToolButton(3  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-sort",   // 字符图标
            "设置顺序",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                setImgOrder( id );

            }
        );



        brick.addToolButton(4  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-rotate-left",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '270', function () { hideInfoPane(); });

            }
        );



    }
}


function rotateImg(sheet, id, degree, callback) {



    let brick = sheet.getBrick('FJ');
    setTimeout(function () {
        //toastr.info(id);  // id 是当前操作的图片对应数据的ID

        do_imageRotate(id, degree, function (ret) {


            if (ret.success) {

                g_turningCount++;
                showInfoPane('*正在旋转图片' + g_turningCount + "/" + g_turnNeedCount + ' ...');


                //把数据中的图片替换，
                for (let i = 0; i < brick.data.length; i++) {
                    if (brick.data[i].id == id) {
                        //属性从新的属性中替换 
                        for (let prop in brick.data[i]) {
                            brick.data[i][prop] = ret.data[prop];
                        }
                        break;
                    }
                }
                //把缩略图的图片地址替换 ， 

                let img = $('#' + id).find('.image');
                img.attr("src", ret.data.url_thumbnail);
                img.attr('largeimage', ret.data.url_img);
                //把大图预览的地址替换掉
                //book.sheet0.cells("imgPreview").setValue(ret.data.url_img);

            }
            if (callback) callback();



        });
    }, 100);

}


function setImgOrder(id)
{
    inputBox( "调整顺序" , "输入本图片的序号" ,"" , "图片顺序号"  , function(v)
    {
        if(  isNaN(v))
        {
            toastr.error("请输入一个数字表示图片的序号");
            return;
        }
        v= parseInt(v);
        back_setImageOrder( id , v, function()
        {
            let brick = sheet.getBrick('FJ');
            brick.reGridly();
        });

    },false); 
}
/**
 * 图片控件中的图片控件顺序发生变化
 * @param sheet   所在Sheet
 * @param name  图片控件的名称
 *@param  ids  当前顺序下的图片的ID数组
 *
 *
 *
 */
//@comment (group=图片控件,caption=图片顺序被改变)
function imageOrderChanged(sheet, name, ids) {

    if (isVerified()) return;  //校对过的不允许再调整顺序

    reOrderImage(ids, function (ret) { }); //放一个空的回调函数让它异步执行，不卡界面

}


var g_selectedAll = false;
function cb_selectallimg_onClick() { g_selectedAll = !g_selectedAll; doSelect(g_selectedAll); }


function doSelect(b) {
    var imgPool = book.sheet2.getBrick('FJ');
    if (b) {
        imgPool.selectAll();
    } else {
        imgPool.unSelectAll();
    }
}


function cb_turnLeft_onClick() {
    turnSelection('270');

}

function cb_turnRight_onClick() {

    turnSelection('90');
}

var g_turningCount = 0;
var g_turnedCount = 0;

function turnSelection(degree) {

    if (isVerified()) return;  //校对过的不允许再旋转

    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    // 当前选中的
    var selection = imgPool.getSelectedImageList();
    if (selection.length == 0) {
        toastr.error("至少选中一张图片");
        return;
    }


    $confirm("提示", "确信要对选中的" + selection.length + "张图片做旋转吗?", function () {

        g_turningCount = 0;
        g_turnedCount = 0;
        g_turnNeedCount = selection.length;
        /*
                setTimeout(function () {
                    for (var i = 0; i < selection.length; i++) {
                        rotateImg(sheet, selection[i].id, degree, i * 1000);
                    }
                }, 10);
                */

        asyncPool(4, selection, function (item, array) {
            return new Promise(function (resolve, reject) {

                console.dir(item);
                rotateImg(sheet, item.id, degree,
                    function () { //注意，在旋转完成后，再设置resolve 表示本任务已完成，而不是直接就resolve ,不然最后的 then 执行时机不对，这么处理，就会在全部旋转完成后，再执行then中的脚本，而不是旋转任务全部发起后就执行 then 
                        resolve(item)
                    });

            });
        }).then(function () {

            setTimeout(function () {

                hideInfoPane();
                toastr.info("旋转完成");
            }, 500);
        });

    });

}




function test1() {


    asyncPool(3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (item, array) {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                console.info(item + "   " + new Date());
                resolve(item)
            }, 1000);

        });
    }).then(function () {
        console.info("over");
    });

}



function ocrTest() {
    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    let imgs = imgPool.getCurrentSortedImageList();//得到当前排序后的图片清单
    let one = imgs[0];

    runTask("pzh-ocr", { src: one.url_img, left: '35%', top: '8%', height: '8%', width: '50%' }, function (text) {
        toastr.info(text);
    });

}


id: 65486120993213e6a7b24eb9
scriptid: 60c4bd735db2478f9c5a111c
tablename: app_template
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 13:42:58.000
script:
var pzh_prefix;
var pzh_length;

var fullScreenDiv = null;



function formOpen() {
    book.showTabOnWhere = 'none';
    //加载帐套信息及年月
    var corpid = book.sheet0.cells("corpid").getValueString();
    runTask("当前记帐期", { corpid: corpid }, function (ym) {
        if (ym == null || ym == 'null') return;
        //得到年月后，获取凭证号相关设置
        pzh_len = getPZHLen(corpid);

        book.sheet0.cells("ym").setValue(ym);

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);


    });

    book.sheet2.getBrick('FJ').selectionMode = 'multi'; //图片设置成多选模式


    // 追加一些CSS类 ，用于凭证号标记
    $(document.body).append(`<style>
                        .pzh {position:absolute;left:0;bottom:0px; 
                                height:24px; line-height:24px;width:100%; 
                                background-color:#40af40a0; 
                                color:white;font-weight:bold;font-size:12px;text-align:center;}
                        .delete_pzh { position:absolute; right:0; width:40px; height:14px; top:0; text-align:right; 
                                    vertical-align:top; font-size:12px; color:gray;padding-right:5px;}      
                        .delete_pzh:hover { color:white;}      
                          
                        </style>
                    `);


}

function cb_check_onClick() {
    smartRetrieve(book.sheet0, "pzh_check", true, false, function () { //检索完后回调
        if ($pzh_check_ds.rowCount == 0) {
            toastr.success("凭证号检测通过");

        } else {
            book.sheet3.popup('fa fa-cog', '缺失的凭证', 250, 350, true, true, {});
        }
    });
}


/**
 * 多行结果集当前焦点行发生变化
 * @param dsname  结果集名称
 * @param row  行号
 */
//@comment (group=单元格事件,caption=单元格行焦点发生变化)
function currentBindRowChanged(dsname, row) {
    if (dsname == 'dzpz_pz') {
        //重新加载凭证图片列表

        let id = $dzpz_pz_ds.getString(row, "id");
        let pzh = $dzpz_pz_ds.getString(row, "pzh");
        loadPZ(pzh, id);

    }
}

function viewPDF(id) {
    var url = get_PZ_PDF_URL(id);
    openWindow(url);
}

/**
 * 单元格的值发生了改变
 * @param sheet  所在的工作表
 * @param cell  单元格对象
 * @param oldValue  原先的值
 * @param newValue 变化后的值
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChanged(sheet, cell, oldValue, newValue, innerRow) {

    //如果是绑定了数据库的，强烈不建议使用本事件，换用结果集变化事件 itemChanged

    //通过别名来判断
    if (cell.alias == 'ym') {
        var corpid = book.sheet0.cells("corpid").getValueString();
        var ym = book.sheet0.cells("ym").getValue();

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);
    }




}

function loadPZ(pzh, id) {

    let data = getPZFJ(id); //得到凭证的所有图片
    let FJ = book.sheet2.getBrick('FJ');
    FJ.buildGridly(data, function () {
        let shortPZH = pzh;//.substring(pzh_prefix.length);
        //加载图片完成后， 如果是凭证，那么加上凭证号信息
        for (let i = 0; i < data.length; i++) {
            if (data[i].groupname == '凭证') {
                setPZH(data[i].id, shortPZH, false);
            }
        }




    });
    g_selectedAll = false; //加载一个凭证的图片后 ，默认是不全选中的
    book.sheet2.yOffset = 0; //垂直卷滚条归位
}


//@comment (group=凭证号,caption=设置图片的凭证号,needRightControl=false)
function setPZH(id, pzh, needDeleteButton) {
    if (needDeleteButton == undefined) needDeleteButton = true
    find_pzh(id, true, needDeleteButton).find('.no').text(pzh);
}

//@comment (group=凭证号,caption=查找或创建凭证号标记对象,needRightControl=false)
function find_pzh(id, create_if_not_exists, needDeleteButton) {

    if (needDeleteButton == undefined) needDeleteButton = true;

    var d = $('#' + id);
    if (!d) {
        $.alert(id + "不存在");
        return null;
    }

    var ret = d.find('.pzh');
    if (ret.length == 0) {
        if (create_if_not_exists) //如果需要创建，则创建它
        {
            d.append(`<div class="pzh" >
                        <div class="no"></div>
                        <div class="delete_pzh"  ${needDeleteButton ? "" : " style='display:none' "} ><i class="fa fa-close" onclick="removePZH('${id}');  event.preventDefault(); event.stopPropagation();"> </i></div>
                      </div>`);
        }
        ret = d.find('.pzh');
    }
    return ret;

}



/**
 * 单元格单击事件
 * @param sheet
 * @param cell
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行被点击
 * @param event 事件对象
 */
//@comment (group=单元格事件,caption=单元格点击)
function cellOnClick(sheet, cell, innerRow, event) {

    //通过别名来判断
    if (cell.alias == 'XXX') {

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'dzpz_pz') {
        if (bind.DBCol == 'c_sh1') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") != 0) return; //已审核，不要再审核
            do_sh1(innerRow, function () {
                if (innerRow < $dzpz_pz_ds.rowCount - 1) {
                    book.getDataSource('dzpz_pz').currentBindRow = innerRow + 1;
                }
            });
        }
        if (bind.DBCol == 'c_sh2') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") == 0) return; //没有审核，不需要取消审核
            do_sh2(innerRow);
        }
    }

}

function do_sh1(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    let pzh = $dzpz_pz_ds.getString(innerRow, "pzh");

    do_sh(id, true, function (ret)  //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", ret.verifierid);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", ret.verifiername);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", ret.verifieddate);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "校对成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "取消校对");

        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}

function do_sh2(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    do_sh(id, false, function (ret) //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", null);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", null);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", null);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "取消成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "校对");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "");


        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}



//@comment (group=工具函数,caption=全选或取消全选)
function seletOrUnSelectAll() {
    //让selection单元格失去编辑焦点，不然再点击，它不会触发单元格的点击事件，因为此时点击的编辑框对象，不会触发单元格的点击
    book.sheet1.View.forceCurrentEditControlGiveUpFocus();

    var v = book.sheet1.cells('selection').getValueInt();

    book.sheet1.paintPermit = false;
    $dzpz_pz_ds.setValueWithTrigger = false;
    for (var i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        $dzpz_pz_ds.setValue(i, "selected", v);
    }
    $dzpz_pz_ds.setValueWithTrigger = true;
    book.sheet1.paintPermit = true;
}


function cb_verify_onClick() {
    $confirm('', '确信要对选中的凭证做审核确认吗?', function () {
        let rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在审核确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在校对确认 " + i);
                do_sh1(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("校对完成");
        });

    });
}



function cb_unverify_onClick() {

    $confirm('', '确信要对选中的凭证做取消校对吗?', function () {
        var rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在取消确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在取消确认" + i);
                do_sh2(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("取消确认完成");
        });

    });


}


function cb_package_onClick() {

    let ids = [];
    for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
        ids.push($dzpz_pz_ds.getString(i, "id"));
    }

    if (ids.length == 0) {
        toastr.info("至少选中一张凭证");
        return;
    }

    $confirm('', '确信要将选中的凭证打包下载吗?', function () {
        showInfoPane("*正在压缩打包...");
        runTask("打包下载", { fileName: formatDate(newDate(), "yyyyMMddHHmm") + ".zip", ids: ids },
            function (ret) {
                ret = JSON.parse(ret);
                hideInfoPane();
                if (ret.success) {
                    openWindow(ret.url);
                } else {
                    toastr.error(ret.message);
                }
            });

    });
}

function isVerified() {
    var row = book.getDataSource('dzpz_pz').currentBindRow;
    var verifiername = $dzpz_pz_ds.getString(row, "verifiername");

    if (verifiername != '') {
        toastr.error("已经校对的凭证不允许执行此操作");
        return true;
    }
    return false;
}


/**
 * 图片控件初始化完成
 * @param sheet   所在Sheet
 * @param config  图片控件的名称
 *@param data  该图片的详细信息
 *
 */
//@comment (group=图片控件,caption=图片控件初始化完成)
function imageGridlyInited(sheet, name, data) {


    if (name == "FJ") {
        //图片都初始化后， 定制右上角的工具栏，最多可加5个工具按 钮
        let brick = sheet.getBrick(name);

        brick.addToolButton(1  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-repeat",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '90', function () { hideInfoPane(); });

            }
        );


        brick.addToolButton(2  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-eye",   // 字符图标
            "浏览大图",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                brick.popupShow(id);

            }
        );


          brick.addToolButton(3  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-sort",   // 字符图标
            "设置顺序",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                setImgOrder( id );

            }
        );



        brick.addToolButton(4  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-rotate-left",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '270', function () { hideInfoPane(); });

            }
        );



    }
}


function rotateImg(sheet, id, degree, callback) {



    let brick = sheet.getBrick('FJ');
    setTimeout(function () {
        //toastr.info(id);  // id 是当前操作的图片对应数据的ID

        do_imageRotate(id, degree, function (ret) {


            if (ret.success) {

                g_turningCount++;
                showInfoPane('*正在旋转图片' + g_turningCount + "/" + g_turnNeedCount + ' ...');


                //把数据中的图片替换，
                for (let i = 0; i < brick.data.length; i++) {
                    if (brick.data[i].id == id) {
                        //属性从新的属性中替换 
                        for (let prop in brick.data[i]) {
                            brick.data[i][prop] = ret.data[prop];
                        }
                        break;
                    }
                }
                //把缩略图的图片地址替换 ， 

                let img = $('#' + id).find('.image');
                img.attr("src", ret.data.url_thumbnail);
                img.attr('largeimage', ret.data.url_img);
                //把大图预览的地址替换掉
                //book.sheet0.cells("imgPreview").setValue(ret.data.url_img);

            }
            if (callback) callback();



        });
    }, 100);

}


function setImgOrder(id)
{
    inputBox( "调整顺序" , "输入本图片的序号" ,"" , "图片顺序号"  , function(v)
    {
        if(  isNaN(v))
        {
            toastr.error("请输入一个数字表示图片的序号");
            return;
        }
        v= parseInt(v);
        back_setImageOrder( id , v, function()
        {
            let brick = sheet.getBrick('FJ');
            brick.rebuildGridly();
        });

    },false); 
}
/**
 * 图片控件中的图片控件顺序发生变化
 * @param sheet   所在Sheet
 * @param name  图片控件的名称
 *@param  ids  当前顺序下的图片的ID数组
 *
 *
 *
 */
//@comment (group=图片控件,caption=图片顺序被改变)
function imageOrderChanged(sheet, name, ids) {

    if (isVerified()) return;  //校对过的不允许再调整顺序

    reOrderImage(ids, function (ret) { }); //放一个空的回调函数让它异步执行，不卡界面

}


var g_selectedAll = false;
function cb_selectallimg_onClick() { g_selectedAll = !g_selectedAll; doSelect(g_selectedAll); }


function doSelect(b) {
    var imgPool = book.sheet2.getBrick('FJ');
    if (b) {
        imgPool.selectAll();
    } else {
        imgPool.unSelectAll();
    }
}


function cb_turnLeft_onClick() {
    turnSelection('270');

}

function cb_turnRight_onClick() {

    turnSelection('90');
}

var g_turningCount = 0;
var g_turnedCount = 0;

function turnSelection(degree) {

    if (isVerified()) return;  //校对过的不允许再旋转

    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    // 当前选中的
    var selection = imgPool.getSelectedImageList();
    if (selection.length == 0) {
        toastr.error("至少选中一张图片");
        return;
    }


    $confirm("提示", "确信要对选中的" + selection.length + "张图片做旋转吗?", function () {

        g_turningCount = 0;
        g_turnedCount = 0;
        g_turnNeedCount = selection.length;
        /*
                setTimeout(function () {
                    for (var i = 0; i < selection.length; i++) {
                        rotateImg(sheet, selection[i].id, degree, i * 1000);
                    }
                }, 10);
                */

        asyncPool(4, selection, function (item, array) {
            return new Promise(function (resolve, reject) {

                console.dir(item);
                rotateImg(sheet, item.id, degree,
                    function () { //注意，在旋转完成后，再设置resolve 表示本任务已完成，而不是直接就resolve ,不然最后的 then 执行时机不对，这么处理，就会在全部旋转完成后，再执行then中的脚本，而不是旋转任务全部发起后就执行 then 
                        resolve(item)
                    });

            });
        }).then(function () {

            setTimeout(function () {

                hideInfoPane();
                toastr.info("旋转完成");
            }, 500);
        });

    });

}




function test1() {


    asyncPool(3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (item, array) {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                console.info(item + "   " + new Date());
                resolve(item)
            }, 1000);

        });
    }).then(function () {
        console.info("over");
    });

}



function ocrTest() {
    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    let imgs = imgPool.getCurrentSortedImageList();//得到当前排序后的图片清单
    let one = imgs[0];

    runTask("pzh-ocr", { src: one.url_img, left: '35%', top: '8%', height: '8%', width: '50%' }, function (text) {
        toastr.info(text);
    });

}


id: 65486120993213e6a7b24ec2
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 13:48:07.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}


function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", "select id ,    info2  from  dzpz_pzfj where  gguid='" + gguid
        + "'  order by info2 asc, groupname ,  info1 asc ");
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        if (i + 1 >= order) ds.setValue(i, "info2", i + 1 + 1);
        if (ds.getString(i, "id") == id) ds.setValue(i, "info2", order);

    }
    ds.update(true);

}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65486120993213e6a7b24ec6
scriptid: 60c4bd735db2478f9c5a111c
tablename: app_template
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 13:50:19.000
script:
var pzh_prefix;
var pzh_length;

var fullScreenDiv = null;



function formOpen() {
    book.showTabOnWhere = 'none';
    //加载帐套信息及年月
    var corpid = book.sheet0.cells("corpid").getValueString();
    runTask("当前记帐期", { corpid: corpid }, function (ym) {
        if (ym == null || ym == 'null') return;
        //得到年月后，获取凭证号相关设置
        pzh_len = getPZHLen(corpid);

        book.sheet0.cells("ym").setValue(ym);

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);


    });

    book.sheet2.getBrick('FJ').selectionMode = 'multi'; //图片设置成多选模式


    // 追加一些CSS类 ，用于凭证号标记
    $(document.body).append(`<style>
                        .pzh {position:absolute;left:0;bottom:0px; 
                                height:24px; line-height:24px;width:100%; 
                                background-color:#40af40a0; 
                                color:white;font-weight:bold;font-size:12px;text-align:center;}
                        .delete_pzh { position:absolute; right:0; width:40px; height:14px; top:0; text-align:right; 
                                    vertical-align:top; font-size:12px; color:gray;padding-right:5px;}      
                        .delete_pzh:hover { color:white;}      
                          
                        </style>
                    `);


}

function cb_check_onClick() {
    smartRetrieve(book.sheet0, "pzh_check", true, false, function () { //检索完后回调
        if ($pzh_check_ds.rowCount == 0) {
            toastr.success("凭证号检测通过");

        } else {
            book.sheet3.popup('fa fa-cog', '缺失的凭证', 250, 350, true, true, {});
        }
    });
}


/**
 * 多行结果集当前焦点行发生变化
 * @param dsname  结果集名称
 * @param row  行号
 */
//@comment (group=单元格事件,caption=单元格行焦点发生变化)
function currentBindRowChanged(dsname, row) {
    if (dsname == 'dzpz_pz') {
        //重新加载凭证图片列表

        let id = $dzpz_pz_ds.getString(row, "id");
        let pzh = $dzpz_pz_ds.getString(row, "pzh");
        loadPZ(pzh, id);

    }
}

function viewPDF(id) {
    var url = get_PZ_PDF_URL(id);
    openWindow(url);
}

/**
 * 单元格的值发生了改变
 * @param sheet  所在的工作表
 * @param cell  单元格对象
 * @param oldValue  原先的值
 * @param newValue 变化后的值
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChanged(sheet, cell, oldValue, newValue, innerRow) {

    //如果是绑定了数据库的，强烈不建议使用本事件，换用结果集变化事件 itemChanged

    //通过别名来判断
    if (cell.alias == 'ym') {
        var corpid = book.sheet0.cells("corpid").getValueString();
        var ym = book.sheet0.cells("ym").getValue();

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);
    }




}

function loadPZ(pzh, id) {

    let data = getPZFJ(id); //得到凭证的所有图片
    let FJ = book.sheet2.getBrick('FJ');
    FJ.buildGridly(data, function () {
        let shortPZH = pzh;//.substring(pzh_prefix.length);
        //加载图片完成后， 如果是凭证，那么加上凭证号信息
        for (let i = 0; i < data.length; i++) {
            if (data[i].groupname == '凭证') {
                setPZH(data[i].id, shortPZH, false);
            }
        }




    });
    g_selectedAll = false; //加载一个凭证的图片后 ，默认是不全选中的
    book.sheet2.yOffset = 0; //垂直卷滚条归位
}


//@comment (group=凭证号,caption=设置图片的凭证号,needRightControl=false)
function setPZH(id, pzh, needDeleteButton) {
    if (needDeleteButton == undefined) needDeleteButton = true
    find_pzh(id, true, needDeleteButton).find('.no').text(pzh);
}

//@comment (group=凭证号,caption=查找或创建凭证号标记对象,needRightControl=false)
function find_pzh(id, create_if_not_exists, needDeleteButton) {

    if (needDeleteButton == undefined) needDeleteButton = true;

    var d = $('#' + id);
    if (!d) {
        $.alert(id + "不存在");
        return null;
    }

    var ret = d.find('.pzh');
    if (ret.length == 0) {
        if (create_if_not_exists) //如果需要创建，则创建它
        {
            d.append(`<div class="pzh" >
                        <div class="no"></div>
                        <div class="delete_pzh"  ${needDeleteButton ? "" : " style='display:none' "} ><i class="fa fa-close" onclick="removePZH('${id}');  event.preventDefault(); event.stopPropagation();"> </i></div>
                      </div>`);
        }
        ret = d.find('.pzh');
    }
    return ret;

}



/**
 * 单元格单击事件
 * @param sheet
 * @param cell
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行被点击
 * @param event 事件对象
 */
//@comment (group=单元格事件,caption=单元格点击)
function cellOnClick(sheet, cell, innerRow, event) {

    //通过别名来判断
    if (cell.alias == 'XXX') {

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'dzpz_pz') {
        if (bind.DBCol == 'c_sh1') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") != 0) return; //已审核，不要再审核
            do_sh1(innerRow, function () {
                if (innerRow < $dzpz_pz_ds.rowCount - 1) {
                    book.getDataSource('dzpz_pz').currentBindRow = innerRow + 1;
                }
            });
        }
        if (bind.DBCol == 'c_sh2') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") == 0) return; //没有审核，不需要取消审核
            do_sh2(innerRow);
        }
    }

}

function do_sh1(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    let pzh = $dzpz_pz_ds.getString(innerRow, "pzh");

    do_sh(id, true, function (ret)  //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", ret.verifierid);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", ret.verifiername);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", ret.verifieddate);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "校对成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "取消校对");

        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}

function do_sh2(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    do_sh(id, false, function (ret) //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", null);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", null);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", null);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "取消成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "校对");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "");


        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}



//@comment (group=工具函数,caption=全选或取消全选)
function seletOrUnSelectAll() {
    //让selection单元格失去编辑焦点，不然再点击，它不会触发单元格的点击事件，因为此时点击的编辑框对象，不会触发单元格的点击
    book.sheet1.View.forceCurrentEditControlGiveUpFocus();

    var v = book.sheet1.cells('selection').getValueInt();

    book.sheet1.paintPermit = false;
    $dzpz_pz_ds.setValueWithTrigger = false;
    for (var i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        $dzpz_pz_ds.setValue(i, "selected", v);
    }
    $dzpz_pz_ds.setValueWithTrigger = true;
    book.sheet1.paintPermit = true;
}


function cb_verify_onClick() {
    $confirm('', '确信要对选中的凭证做审核确认吗?', function () {
        let rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在审核确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在校对确认 " + i);
                do_sh1(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("校对完成");
        });

    });
}



function cb_unverify_onClick() {

    $confirm('', '确信要对选中的凭证做取消校对吗?', function () {
        var rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在取消确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在取消确认" + i);
                do_sh2(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("取消确认完成");
        });

    });


}


function cb_package_onClick() {

    let ids = [];
    for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
        ids.push($dzpz_pz_ds.getString(i, "id"));
    }

    if (ids.length == 0) {
        toastr.info("至少选中一张凭证");
        return;
    }

    $confirm('', '确信要将选中的凭证打包下载吗?', function () {
        showInfoPane("*正在压缩打包...");
        runTask("打包下载", { fileName: formatDate(newDate(), "yyyyMMddHHmm") + ".zip", ids: ids },
            function (ret) {
                ret = JSON.parse(ret);
                hideInfoPane();
                if (ret.success) {
                    openWindow(ret.url);
                } else {
                    toastr.error(ret.message);
                }
            });

    });
}

function isVerified() {
    var row = book.getDataSource('dzpz_pz').currentBindRow;
    var verifiername = $dzpz_pz_ds.getString(row, "verifiername");

    if (verifiername != '') {
        toastr.error("已经校对的凭证不允许执行此操作");
        return true;
    }
    return false;
}


/**
 * 图片控件初始化完成
 * @param sheet   所在Sheet
 * @param config  图片控件的名称
 *@param data  该图片的详细信息
 *
 */
//@comment (group=图片控件,caption=图片控件初始化完成)
function imageGridlyInited(sheet, name, data) {


    if (name == "FJ") {
        //图片都初始化后， 定制右上角的工具栏，最多可加5个工具按 钮
        let brick = sheet.getBrick(name);

        brick.addToolButton(1  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-repeat",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '90', function () { hideInfoPane(); });

            }
        );


        brick.addToolButton(2  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-eye",   // 字符图标
            "浏览大图",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                brick.popupShow(id);

            }
        );


          brick.addToolButton(3  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-sort",   // 字符图标
            "设置顺序",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                setImgOrder( id );

            }
        );



        brick.addToolButton(4  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-rotate-left",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '270', function () { hideInfoPane(); });

            }
        );



    }
}


function rotateImg(sheet, id, degree, callback) {



    let brick = sheet.getBrick('FJ');
    setTimeout(function () {
        //toastr.info(id);  // id 是当前操作的图片对应数据的ID

        do_imageRotate(id, degree, function (ret) {


            if (ret.success) {

                g_turningCount++;
                showInfoPane('*正在旋转图片' + g_turningCount + "/" + g_turnNeedCount + ' ...');


                //把数据中的图片替换，
                for (let i = 0; i < brick.data.length; i++) {
                    if (brick.data[i].id == id) {
                        //属性从新的属性中替换 
                        for (let prop in brick.data[i]) {
                            brick.data[i][prop] = ret.data[prop];
                        }
                        break;
                    }
                }
                //把缩略图的图片地址替换 ， 

                let img = $('#' + id).find('.image');
                img.attr("src", ret.data.url_thumbnail);
                img.attr('largeimage', ret.data.url_img);
                //把大图预览的地址替换掉
                //book.sheet0.cells("imgPreview").setValue(ret.data.url_img);

            }
            if (callback) callback();



        });
    }, 100);

}


function setImgOrder(id)
{
    inputBox( "调整顺序" , "输入本图片的序号" ,"" , "图片顺序号"  , function(v)
    {
        if(  isNaN(v))
        {
            toastr.error("请输入一个数字表示图片的序号");
            return;
        }
        v= parseInt(v);

         let row=  book.getDataSource('dzpz_pz').currentBindRow;
         let gguid = $dzpz_pz_ds.getString(row, "id");

        back_setImageOrder( gguid, id , v, function()
        {
            let brick = sheet.getBrick('FJ');
            brick.rebuildGridly();
        });

    },false); 
}
/**
 * 图片控件中的图片控件顺序发生变化
 * @param sheet   所在Sheet
 * @param name  图片控件的名称
 *@param  ids  当前顺序下的图片的ID数组
 *
 *
 *
 */
//@comment (group=图片控件,caption=图片顺序被改变)
function imageOrderChanged(sheet, name, ids) {

    if (isVerified()) return;  //校对过的不允许再调整顺序

    reOrderImage(ids, function (ret) { }); //放一个空的回调函数让它异步执行，不卡界面

}


var g_selectedAll = false;
function cb_selectallimg_onClick() { g_selectedAll = !g_selectedAll; doSelect(g_selectedAll); }


function doSelect(b) {
    var imgPool = book.sheet2.getBrick('FJ');
    if (b) {
        imgPool.selectAll();
    } else {
        imgPool.unSelectAll();
    }
}


function cb_turnLeft_onClick() {
    turnSelection('270');

}

function cb_turnRight_onClick() {

    turnSelection('90');
}

var g_turningCount = 0;
var g_turnedCount = 0;

function turnSelection(degree) {

    if (isVerified()) return;  //校对过的不允许再旋转

    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    // 当前选中的
    var selection = imgPool.getSelectedImageList();
    if (selection.length == 0) {
        toastr.error("至少选中一张图片");
        return;
    }


    $confirm("提示", "确信要对选中的" + selection.length + "张图片做旋转吗?", function () {

        g_turningCount = 0;
        g_turnedCount = 0;
        g_turnNeedCount = selection.length;
        /*
                setTimeout(function () {
                    for (var i = 0; i < selection.length; i++) {
                        rotateImg(sheet, selection[i].id, degree, i * 1000);
                    }
                }, 10);
                */

        asyncPool(4, selection, function (item, array) {
            return new Promise(function (resolve, reject) {

                console.dir(item);
                rotateImg(sheet, item.id, degree,
                    function () { //注意，在旋转完成后，再设置resolve 表示本任务已完成，而不是直接就resolve ,不然最后的 then 执行时机不对，这么处理，就会在全部旋转完成后，再执行then中的脚本，而不是旋转任务全部发起后就执行 then 
                        resolve(item)
                    });

            });
        }).then(function () {

            setTimeout(function () {

                hideInfoPane();
                toastr.info("旋转完成");
            }, 500);
        });

    });

}




function test1() {


    asyncPool(3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (item, array) {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                console.info(item + "   " + new Date());
                resolve(item)
            }, 1000);

        });
    }).then(function () {
        console.info("over");
    });

}



function ocrTest() {
    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    let imgs = imgPool.getCurrentSortedImageList();//得到当前排序后的图片清单
    let one = imgs[0];

    runTask("pzh-ocr", { src: one.url_img, left: '35%', top: '8%', height: '8%', width: '50%' }, function (text) {
        toastr.info(text);
    });

}


id: 65486120993213e6a7b24eca
scriptid: 60c4bd735db2478f9c5a111c
tablename: app_template
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 13:50:27.000
script:
var pzh_prefix;
var pzh_length;

var fullScreenDiv = null;



function formOpen() {
    book.showTabOnWhere = 'none';
    //加载帐套信息及年月
    var corpid = book.sheet0.cells("corpid").getValueString();
    runTask("当前记帐期", { corpid: corpid }, function (ym) {
        if (ym == null || ym == 'null') return;
        //得到年月后，获取凭证号相关设置
        pzh_len = getPZHLen(corpid);

        book.sheet0.cells("ym").setValue(ym);

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);


    });

    book.sheet2.getBrick('FJ').selectionMode = 'multi'; //图片设置成多选模式


    // 追加一些CSS类 ，用于凭证号标记
    $(document.body).append(`<style>
                        .pzh {position:absolute;left:0;bottom:0px; 
                                height:24px; line-height:24px;width:100%; 
                                background-color:#40af40a0; 
                                color:white;font-weight:bold;font-size:12px;text-align:center;}
                        .delete_pzh { position:absolute; right:0; width:40px; height:14px; top:0; text-align:right; 
                                    vertical-align:top; font-size:12px; color:gray;padding-right:5px;}      
                        .delete_pzh:hover { color:white;}      
                          
                        </style>
                    `);


}

function cb_check_onClick() {
    smartRetrieve(book.sheet0, "pzh_check", true, false, function () { //检索完后回调
        if ($pzh_check_ds.rowCount == 0) {
            toastr.success("凭证号检测通过");

        } else {
            book.sheet3.popup('fa fa-cog', '缺失的凭证', 250, 350, true, true, {});
        }
    });
}


/**
 * 多行结果集当前焦点行发生变化
 * @param dsname  结果集名称
 * @param row  行号
 */
//@comment (group=单元格事件,caption=单元格行焦点发生变化)
function currentBindRowChanged(dsname, row) {
    if (dsname == 'dzpz_pz') {
        //重新加载凭证图片列表

        let id = $dzpz_pz_ds.getString(row, "id");
        let pzh = $dzpz_pz_ds.getString(row, "pzh");
        loadPZ(pzh, id);

    }
}

function viewPDF(id) {
    var url = get_PZ_PDF_URL(id);
    openWindow(url);
}

/**
 * 单元格的值发生了改变
 * @param sheet  所在的工作表
 * @param cell  单元格对象
 * @param oldValue  原先的值
 * @param newValue 变化后的值
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChanged(sheet, cell, oldValue, newValue, innerRow) {

    //如果是绑定了数据库的，强烈不建议使用本事件，换用结果集变化事件 itemChanged

    //通过别名来判断
    if (cell.alias == 'ym') {
        var corpid = book.sheet0.cells("corpid").getValueString();
        var ym = book.sheet0.cells("ym").getValue();

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);
    }




}

function loadPZ(pzh, id) {

    let data = getPZFJ(id); //得到凭证的所有图片
    let FJ = book.sheet2.getBrick('FJ');
    FJ.buildGridly(data, function () {
        let shortPZH = pzh;//.substring(pzh_prefix.length);
        //加载图片完成后， 如果是凭证，那么加上凭证号信息
        for (let i = 0; i < data.length; i++) {
            if (data[i].groupname == '凭证') {
                setPZH(data[i].id, shortPZH, false);
            }
        }




    });
    g_selectedAll = false; //加载一个凭证的图片后 ，默认是不全选中的
    book.sheet2.yOffset = 0; //垂直卷滚条归位
}


//@comment (group=凭证号,caption=设置图片的凭证号,needRightControl=false)
function setPZH(id, pzh, needDeleteButton) {
    if (needDeleteButton == undefined) needDeleteButton = true
    find_pzh(id, true, needDeleteButton).find('.no').text(pzh);
}

//@comment (group=凭证号,caption=查找或创建凭证号标记对象,needRightControl=false)
function find_pzh(id, create_if_not_exists, needDeleteButton) {

    if (needDeleteButton == undefined) needDeleteButton = true;

    var d = $('#' + id);
    if (!d) {
        $.alert(id + "不存在");
        return null;
    }

    var ret = d.find('.pzh');
    if (ret.length == 0) {
        if (create_if_not_exists) //如果需要创建，则创建它
        {
            d.append(`<div class="pzh" >
                        <div class="no"></div>
                        <div class="delete_pzh"  ${needDeleteButton ? "" : " style='display:none' "} ><i class="fa fa-close" onclick="removePZH('${id}');  event.preventDefault(); event.stopPropagation();"> </i></div>
                      </div>`);
        }
        ret = d.find('.pzh');
    }
    return ret;

}



/**
 * 单元格单击事件
 * @param sheet
 * @param cell
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行被点击
 * @param event 事件对象
 */
//@comment (group=单元格事件,caption=单元格点击)
function cellOnClick(sheet, cell, innerRow, event) {

    //通过别名来判断
    if (cell.alias == 'XXX') {

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'dzpz_pz') {
        if (bind.DBCol == 'c_sh1') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") != 0) return; //已审核，不要再审核
            do_sh1(innerRow, function () {
                if (innerRow < $dzpz_pz_ds.rowCount - 1) {
                    book.getDataSource('dzpz_pz').currentBindRow = innerRow + 1;
                }
            });
        }
        if (bind.DBCol == 'c_sh2') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") == 0) return; //没有审核，不需要取消审核
            do_sh2(innerRow);
        }
    }

}

function do_sh1(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    let pzh = $dzpz_pz_ds.getString(innerRow, "pzh");

    do_sh(id, true, function (ret)  //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", ret.verifierid);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", ret.verifiername);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", ret.verifieddate);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "校对成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "取消校对");

        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}

function do_sh2(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    do_sh(id, false, function (ret) //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", null);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", null);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", null);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "取消成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "校对");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "");


        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}



//@comment (group=工具函数,caption=全选或取消全选)
function seletOrUnSelectAll() {
    //让selection单元格失去编辑焦点，不然再点击，它不会触发单元格的点击事件，因为此时点击的编辑框对象，不会触发单元格的点击
    book.sheet1.View.forceCurrentEditControlGiveUpFocus();

    var v = book.sheet1.cells('selection').getValueInt();

    book.sheet1.paintPermit = false;
    $dzpz_pz_ds.setValueWithTrigger = false;
    for (var i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        $dzpz_pz_ds.setValue(i, "selected", v);
    }
    $dzpz_pz_ds.setValueWithTrigger = true;
    book.sheet1.paintPermit = true;
}


function cb_verify_onClick() {
    $confirm('', '确信要对选中的凭证做审核确认吗?', function () {
        let rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在审核确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在校对确认 " + i);
                do_sh1(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("校对完成");
        });

    });
}



function cb_unverify_onClick() {

    $confirm('', '确信要对选中的凭证做取消校对吗?', function () {
        var rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在取消确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在取消确认" + i);
                do_sh2(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("取消确认完成");
        });

    });


}


function cb_package_onClick() {

    let ids = [];
    for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
        ids.push($dzpz_pz_ds.getString(i, "id"));
    }

    if (ids.length == 0) {
        toastr.info("至少选中一张凭证");
        return;
    }

    $confirm('', '确信要将选中的凭证打包下载吗?', function () {
        showInfoPane("*正在压缩打包...");
        runTask("打包下载", { fileName: formatDate(newDate(), "yyyyMMddHHmm") + ".zip", ids: ids },
            function (ret) {
                ret = JSON.parse(ret);
                hideInfoPane();
                if (ret.success) {
                    openWindow(ret.url);
                } else {
                    toastr.error(ret.message);
                }
            });

    });
}

function isVerified() {
    var row = book.getDataSource('dzpz_pz').currentBindRow;
    var verifiername = $dzpz_pz_ds.getString(row, "verifiername");

    if (verifiername != '') {
        toastr.error("已经校对的凭证不允许执行此操作");
        return true;
    }
    return false;
}


/**
 * 图片控件初始化完成
 * @param sheet   所在Sheet
 * @param config  图片控件的名称
 *@param data  该图片的详细信息
 *
 */
//@comment (group=图片控件,caption=图片控件初始化完成)
function imageGridlyInited(sheet, name, data) {


    if (name == "FJ") {
        //图片都初始化后， 定制右上角的工具栏，最多可加5个工具按 钮
        let brick = sheet.getBrick(name);

        brick.addToolButton(1  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-repeat",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '90', function () { hideInfoPane(); });

            }
        );


        brick.addToolButton(2  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-eye",   // 字符图标
            "浏览大图",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                brick.popupShow(id);

            }
        );


        brick.addToolButton(3  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-sort",   // 字符图标
            "设置顺序",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                setImgOrder(id);

            }
        );



        brick.addToolButton(4  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-rotate-left",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '270', function () { hideInfoPane(); });

            }
        );



    }
}


function rotateImg(sheet, id, degree, callback) {



    let brick = sheet.getBrick('FJ');
    setTimeout(function () {
        //toastr.info(id);  // id 是当前操作的图片对应数据的ID

        do_imageRotate(id, degree, function (ret) {


            if (ret.success) {

                g_turningCount++;
                showInfoPane('*正在旋转图片' + g_turningCount + "/" + g_turnNeedCount + ' ...');


                //把数据中的图片替换，
                for (let i = 0; i < brick.data.length; i++) {
                    if (brick.data[i].id == id) {
                        //属性从新的属性中替换 
                        for (let prop in brick.data[i]) {
                            brick.data[i][prop] = ret.data[prop];
                        }
                        break;
                    }
                }
                //把缩略图的图片地址替换 ， 

                let img = $('#' + id).find('.image');
                img.attr("src", ret.data.url_thumbnail);
                img.attr('largeimage', ret.data.url_img);
                //把大图预览的地址替换掉
                //book.sheet0.cells("imgPreview").setValue(ret.data.url_img);

            }
            if (callback) callback();



        });
    }, 100);

}


function setImgOrder(id) {
    inputBox("调整顺序", "输入本图片的序号", "", "图片顺序号", function (v) {
        if (isNaN(v)) {
            toastr.error("请输入一个数字表示图片的序号");
            return;
        }
        v = parseInt(v);

        let row = book.getDataSource('dzpz_pz').currentBindRow;
        let gguid = $dzpz_pz_ds.getString(row, "id");

        back_setImageOrder(gguid, id, v, function () {
            let brick = sheet.getBrick('FJ');
            brick.rebuildGridly();
        });

    }, false);
}
/**
 * 图片控件中的图片控件顺序发生变化
 * @param sheet   所在Sheet
 * @param name  图片控件的名称
 *@param  ids  当前顺序下的图片的ID数组
 *
 *
 *
 */
//@comment (group=图片控件,caption=图片顺序被改变)
function imageOrderChanged(sheet, name, ids) {

    if (isVerified()) return;  //校对过的不允许再调整顺序

    reOrderImage(ids, function (ret) { }); //放一个空的回调函数让它异步执行，不卡界面

}


var g_selectedAll = false;
function cb_selectallimg_onClick() { g_selectedAll = !g_selectedAll; doSelect(g_selectedAll); }


function doSelect(b) {
    var imgPool = book.sheet2.getBrick('FJ');
    if (b) {
        imgPool.selectAll();
    } else {
        imgPool.unSelectAll();
    }
}


function cb_turnLeft_onClick() {
    turnSelection('270');

}

function cb_turnRight_onClick() {

    turnSelection('90');
}

var g_turningCount = 0;
var g_turnedCount = 0;

function turnSelection(degree) {

    if (isVerified()) return;  //校对过的不允许再旋转

    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    // 当前选中的
    var selection = imgPool.getSelectedImageList();
    if (selection.length == 0) {
        toastr.error("至少选中一张图片");
        return;
    }


    $confirm("提示", "确信要对选中的" + selection.length + "张图片做旋转吗?", function () {

        g_turningCount = 0;
        g_turnedCount = 0;
        g_turnNeedCount = selection.length;
        /*
                setTimeout(function () {
                    for (var i = 0; i < selection.length; i++) {
                        rotateImg(sheet, selection[i].id, degree, i * 1000);
                    }
                }, 10);
                */

        asyncPool(4, selection, function (item, array) {
            return new Promise(function (resolve, reject) {

                console.dir(item);
                rotateImg(sheet, item.id, degree,
                    function () { //注意，在旋转完成后，再设置resolve 表示本任务已完成，而不是直接就resolve ,不然最后的 then 执行时机不对，这么处理，就会在全部旋转完成后，再执行then中的脚本，而不是旋转任务全部发起后就执行 then 
                        resolve(item)
                    });

            });
        }).then(function () {

            setTimeout(function () {

                hideInfoPane();
                toastr.info("旋转完成");
            }, 500);
        });

    });

}




function test1() {


    asyncPool(3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (item, array) {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                console.info(item + "   " + new Date());
                resolve(item)
            }, 1000);

        });
    }).then(function () {
        console.info("over");
    });

}



function ocrTest() {
    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    let imgs = imgPool.getCurrentSortedImageList();//得到当前排序后的图片清单
    let one = imgs[0];

    runTask("pzh-ocr", { src: one.url_img, left: '35%', top: '8%', height: '8%', width: '50%' }, function (text) {
        toastr.info(text);
    });

}


id: 65486120993213e6a7b24ed5
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 13:55:59.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}


function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", "select id ,    info2  from  dzpz_pzfj where  gguid='" + gguid
        + "'  order by info2 asc, groupname ,  info1 asc ");
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {
        ds.setValue(i, "info2", i + 1  );
        if (i + 1 >= order) ds.setValue(i, "info2", i + 1 + 1);
        if (ds.getString(i, "id") == id) ds.setValue(i, "info2", order);

    }
    ds.update(true);

}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65486120993213e6a7b24edb
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 13:56:12.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}


function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", "select id ,    info2  from  dzpz_pzfj where  gguid='" + gguid
        + "'  order by info2 asc, groupname ,  info1 asc ");
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println( n); 

    var ret = [];
    for (var i = 0; i < n; i++) {
        ds.setValue(i, "info2", i + 1  );
        if (i + 1 >= order) ds.setValue(i, "info2", i + 1 + 1);
        if (ds.getString(i, "id") == id) ds.setValue(i, "info2", order);

    }
    ds.update(true);

}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65486120993213e6a7b24ee1
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 13:56:36.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}


function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", "select id ,    info2  from  dzpz_pzfj where  gguid='" + gguid
        + "'  order by info2 asc, groupname ,  info1 asc ");
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println( n); 

    var ret = [];
    for (var i = 0; i < n; i++) {
        ds.setValue(i, "info2", i + 1  );
        if (i + 1 >= order) ds.setValue(i, "info2", i + 1 + 1);
        if (ds.getString(i, "id") == id) ds.setValue(i, "info2", order);

    }
    ds.update(true);
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65486120993213e6a7b24ee5
scriptid: 60c4bd735db2478f9c5a111c
tablename: app_template
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 13:57:12.000
script:
var pzh_prefix;
var pzh_length;

var fullScreenDiv = null;



function formOpen() {
    book.showTabOnWhere = 'none';
    //加载帐套信息及年月
    var corpid = book.sheet0.cells("corpid").getValueString();
    runTask("当前记帐期", { corpid: corpid }, function (ym) {
        if (ym == null || ym == 'null') return;
        //得到年月后，获取凭证号相关设置
        pzh_len = getPZHLen(corpid);

        book.sheet0.cells("ym").setValue(ym);

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);


    });

    book.sheet2.getBrick('FJ').selectionMode = 'multi'; //图片设置成多选模式


    // 追加一些CSS类 ，用于凭证号标记
    $(document.body).append(`<style>
                        .pzh {position:absolute;left:0;bottom:0px; 
                                height:24px; line-height:24px;width:100%; 
                                background-color:#40af40a0; 
                                color:white;font-weight:bold;font-size:12px;text-align:center;}
                        .delete_pzh { position:absolute; right:0; width:40px; height:14px; top:0; text-align:right; 
                                    vertical-align:top; font-size:12px; color:gray;padding-right:5px;}      
                        .delete_pzh:hover { color:white;}      
                          
                        </style>
                    `);


}

function cb_check_onClick() {
    smartRetrieve(book.sheet0, "pzh_check", true, false, function () { //检索完后回调
        if ($pzh_check_ds.rowCount == 0) {
            toastr.success("凭证号检测通过");

        } else {
            book.sheet3.popup('fa fa-cog', '缺失的凭证', 250, 350, true, true, {});
        }
    });
}


/**
 * 多行结果集当前焦点行发生变化
 * @param dsname  结果集名称
 * @param row  行号
 */
//@comment (group=单元格事件,caption=单元格行焦点发生变化)
function currentBindRowChanged(dsname, row) {
    if (dsname == 'dzpz_pz') {
        //重新加载凭证图片列表

        let id = $dzpz_pz_ds.getString(row, "id");
        let pzh = $dzpz_pz_ds.getString(row, "pzh");
        loadPZ(pzh, id);

    }
}

function viewPDF(id) {
    var url = get_PZ_PDF_URL(id);
    openWindow(url);
}

/**
 * 单元格的值发生了改变
 * @param sheet  所在的工作表
 * @param cell  单元格对象
 * @param oldValue  原先的值
 * @param newValue 变化后的值
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChanged(sheet, cell, oldValue, newValue, innerRow) {

    //如果是绑定了数据库的，强烈不建议使用本事件，换用结果集变化事件 itemChanged

    //通过别名来判断
    if (cell.alias == 'ym') {
        var corpid = book.sheet0.cells("corpid").getValueString();
        var ym = book.sheet0.cells("ym").getValue();

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);
    }




}

function loadPZ(pzh, id) {

    let data = getPZFJ(id); //得到凭证的所有图片
    let FJ = book.sheet2.getBrick('FJ');
    FJ.buildGridly(data, function () {
        let shortPZH = pzh;//.substring(pzh_prefix.length);
        //加载图片完成后， 如果是凭证，那么加上凭证号信息
        for (let i = 0; i < data.length; i++) {
            if (data[i].groupname == '凭证') {
                setPZH(data[i].id, shortPZH, false);
            }
        }




    });
    g_selectedAll = false; //加载一个凭证的图片后 ，默认是不全选中的
    book.sheet2.yOffset = 0; //垂直卷滚条归位
}


//@comment (group=凭证号,caption=设置图片的凭证号,needRightControl=false)
function setPZH(id, pzh, needDeleteButton) {
    if (needDeleteButton == undefined) needDeleteButton = true
    find_pzh(id, true, needDeleteButton).find('.no').text(pzh);
}

//@comment (group=凭证号,caption=查找或创建凭证号标记对象,needRightControl=false)
function find_pzh(id, create_if_not_exists, needDeleteButton) {

    if (needDeleteButton == undefined) needDeleteButton = true;

    var d = $('#' + id);
    if (!d) {
        $.alert(id + "不存在");
        return null;
    }

    var ret = d.find('.pzh');
    if (ret.length == 0) {
        if (create_if_not_exists) //如果需要创建，则创建它
        {
            d.append(`<div class="pzh" >
                        <div class="no"></div>
                        <div class="delete_pzh"  ${needDeleteButton ? "" : " style='display:none' "} ><i class="fa fa-close" onclick="removePZH('${id}');  event.preventDefault(); event.stopPropagation();"> </i></div>
                      </div>`);
        }
        ret = d.find('.pzh');
    }
    return ret;

}



/**
 * 单元格单击事件
 * @param sheet
 * @param cell
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行被点击
 * @param event 事件对象
 */
//@comment (group=单元格事件,caption=单元格点击)
function cellOnClick(sheet, cell, innerRow, event) {

    //通过别名来判断
    if (cell.alias == 'XXX') {

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'dzpz_pz') {
        if (bind.DBCol == 'c_sh1') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") != 0) return; //已审核，不要再审核
            do_sh1(innerRow, function () {
                if (innerRow < $dzpz_pz_ds.rowCount - 1) {
                    book.getDataSource('dzpz_pz').currentBindRow = innerRow + 1;
                }
            });
        }
        if (bind.DBCol == 'c_sh2') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") == 0) return; //没有审核，不需要取消审核
            do_sh2(innerRow);
        }
    }

}

function do_sh1(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    let pzh = $dzpz_pz_ds.getString(innerRow, "pzh");

    do_sh(id, true, function (ret)  //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", ret.verifierid);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", ret.verifiername);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", ret.verifieddate);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "校对成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "取消校对");

        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}

function do_sh2(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    do_sh(id, false, function (ret) //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", null);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", null);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", null);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "取消成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "校对");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "");


        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}



//@comment (group=工具函数,caption=全选或取消全选)
function seletOrUnSelectAll() {
    //让selection单元格失去编辑焦点，不然再点击，它不会触发单元格的点击事件，因为此时点击的编辑框对象，不会触发单元格的点击
    book.sheet1.View.forceCurrentEditControlGiveUpFocus();

    var v = book.sheet1.cells('selection').getValueInt();

    book.sheet1.paintPermit = false;
    $dzpz_pz_ds.setValueWithTrigger = false;
    for (var i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        $dzpz_pz_ds.setValue(i, "selected", v);
    }
    $dzpz_pz_ds.setValueWithTrigger = true;
    book.sheet1.paintPermit = true;
}


function cb_verify_onClick() {
    $confirm('', '确信要对选中的凭证做审核确认吗?', function () {
        let rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在审核确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在校对确认 " + i);
                do_sh1(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("校对完成");
        });

    });
}



function cb_unverify_onClick() {

    $confirm('', '确信要对选中的凭证做取消校对吗?', function () {
        var rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在取消确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在取消确认" + i);
                do_sh2(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("取消确认完成");
        });

    });


}


function cb_package_onClick() {

    let ids = [];
    for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
        ids.push($dzpz_pz_ds.getString(i, "id"));
    }

    if (ids.length == 0) {
        toastr.info("至少选中一张凭证");
        return;
    }

    $confirm('', '确信要将选中的凭证打包下载吗?', function () {
        showInfoPane("*正在压缩打包...");
        runTask("打包下载", { fileName: formatDate(newDate(), "yyyyMMddHHmm") + ".zip", ids: ids },
            function (ret) {
                ret = JSON.parse(ret);
                hideInfoPane();
                if (ret.success) {
                    openWindow(ret.url);
                } else {
                    toastr.error(ret.message);
                }
            });

    });
}

function isVerified() {
    var row = book.getDataSource('dzpz_pz').currentBindRow;
    var verifiername = $dzpz_pz_ds.getString(row, "verifiername");

    if (verifiername != '') {
        toastr.error("已经校对的凭证不允许执行此操作");
        return true;
    }
    return false;
}


/**
 * 图片控件初始化完成
 * @param sheet   所在Sheet
 * @param config  图片控件的名称
 *@param data  该图片的详细信息
 *
 */
//@comment (group=图片控件,caption=图片控件初始化完成)
function imageGridlyInited(sheet, name, data) {


    if (name == "FJ") {
        //图片都初始化后， 定制右上角的工具栏，最多可加5个工具按 钮
        let brick = sheet.getBrick(name);

        brick.addToolButton(1  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-repeat",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '90', function () { hideInfoPane(); });

            }
        );


        brick.addToolButton(2  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-eye",   // 字符图标
            "浏览大图",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                brick.popupShow(id);

            }
        );


        brick.addToolButton(3  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-sort",   // 字符图标
            "设置顺序",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                setImgOrder(id);

            }
        );



        brick.addToolButton(4  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-rotate-left",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '270', function () { hideInfoPane(); });

            }
        );



    }
}


function rotateImg(sheet, id, degree, callback) {



    let brick = sheet.getBrick('FJ');
    setTimeout(function () {
        //toastr.info(id);  // id 是当前操作的图片对应数据的ID

        do_imageRotate(id, degree, function (ret) {


            if (ret.success) {

                g_turningCount++;
                showInfoPane('*正在旋转图片' + g_turningCount + "/" + g_turnNeedCount + ' ...');


                //把数据中的图片替换，
                for (let i = 0; i < brick.data.length; i++) {
                    if (brick.data[i].id == id) {
                        //属性从新的属性中替换 
                        for (let prop in brick.data[i]) {
                            brick.data[i][prop] = ret.data[prop];
                        }
                        break;
                    }
                }
                //把缩略图的图片地址替换 ， 

                let img = $('#' + id).find('.image');
                img.attr("src", ret.data.url_thumbnail);
                img.attr('largeimage', ret.data.url_img);
                //把大图预览的地址替换掉
                //book.sheet0.cells("imgPreview").setValue(ret.data.url_img);

            }
            if (callback) callback();



        });
    }, 100);

}


function setImgOrder(id) {
    inputBox("调整顺序", "输入本图片的序号", "", "图片顺序号", function (v) {
        if (isNaN(v)) {
            toastr.error("请输入一个数字表示图片的序号");
            return;
        }
        v = parseInt(v);

        let row = book.getDataSource('dzpz_pz').currentBindRow;
        let gguid = $dzpz_pz_ds.getString(row, "id");

        back_setImageOrder(gguid, id, v, function () {
            let brick = book.sheet2.getBrick('FJ');
            brick.rebuildGridly();
        });

    }, false);
}
/**
 * 图片控件中的图片控件顺序发生变化
 * @param sheet   所在Sheet
 * @param name  图片控件的名称
 *@param  ids  当前顺序下的图片的ID数组
 *
 *
 *
 */
//@comment (group=图片控件,caption=图片顺序被改变)
function imageOrderChanged(sheet, name, ids) {

    if (isVerified()) return;  //校对过的不允许再调整顺序

    reOrderImage(ids, function (ret) { }); //放一个空的回调函数让它异步执行，不卡界面

}


var g_selectedAll = false;
function cb_selectallimg_onClick() { g_selectedAll = !g_selectedAll; doSelect(g_selectedAll); }


function doSelect(b) {
    var imgPool = book.sheet2.getBrick('FJ');
    if (b) {
        imgPool.selectAll();
    } else {
        imgPool.unSelectAll();
    }
}


function cb_turnLeft_onClick() {
    turnSelection('270');

}

function cb_turnRight_onClick() {

    turnSelection('90');
}

var g_turningCount = 0;
var g_turnedCount = 0;

function turnSelection(degree) {

    if (isVerified()) return;  //校对过的不允许再旋转

    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    // 当前选中的
    var selection = imgPool.getSelectedImageList();
    if (selection.length == 0) {
        toastr.error("至少选中一张图片");
        return;
    }


    $confirm("提示", "确信要对选中的" + selection.length + "张图片做旋转吗?", function () {

        g_turningCount = 0;
        g_turnedCount = 0;
        g_turnNeedCount = selection.length;
        /*
                setTimeout(function () {
                    for (var i = 0; i < selection.length; i++) {
                        rotateImg(sheet, selection[i].id, degree, i * 1000);
                    }
                }, 10);
                */

        asyncPool(4, selection, function (item, array) {
            return new Promise(function (resolve, reject) {

                console.dir(item);
                rotateImg(sheet, item.id, degree,
                    function () { //注意，在旋转完成后，再设置resolve 表示本任务已完成，而不是直接就resolve ,不然最后的 then 执行时机不对，这么处理，就会在全部旋转完成后，再执行then中的脚本，而不是旋转任务全部发起后就执行 then 
                        resolve(item)
                    });

            });
        }).then(function () {

            setTimeout(function () {

                hideInfoPane();
                toastr.info("旋转完成");
            }, 500);
        });

    });

}




function test1() {


    asyncPool(3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (item, array) {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                console.info(item + "   " + new Date());
                resolve(item)
            }, 1000);

        });
    }).then(function () {
        console.info("over");
    });

}



function ocrTest() {
    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    let imgs = imgPool.getCurrentSortedImageList();//得到当前排序后的图片清单
    let one = imgs[0];

    runTask("pzh-ocr", { src: one.url_img, left: '35%', top: '8%', height: '8%', width: '50%' }, function (text) {
        toastr.info(text);
    });

}


id: 65486120993213e6a7b24eef
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 14:00:06.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}


function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", "select id ,    info2  from  dzpz_pzfj where  gguid='" + gguid
        + "'  order by info2 asc, groupname ,  info1 asc ");
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println( n); 

    var ret = [];
    for (var i = 0; i < n; i++) {
        ds.setValue(i, "info2", i + 1  );
        if (i + 1 >= order) ds.setValue(i, "info2", i + 1 + 1);
        if (ds.getString(i, "id") == id) ds.setValue(i, "info2", order);

    }
    
    if( !ds.update(true)) println( ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65486120993213e6a7b24ef5
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 14:02:30.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", "select id ,    info2  from  dzpz_pzfj where  gguid='" + gguid
        + "'  order by info2 asc, groupname ,  info1 asc ");
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    var ret = [];
    for (var i = 0; i < n; i++) {
        var xh = right('0000' + (i + 1), 4);

        if (i + 1 >= order) xh = right('0000' + (i + 1 + 1), 4);

        if (ds.getString(i, "id") == id) xh = right('0000' + (order), 4);
        ds.setValue(i, "info2", xh);

    }

    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65486120993213e6a7b24efb
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 14:04:27.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select id , info2  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    var ret = [];
    for (var i = 0; i < n; i++) {
        var xh = right('0000' + (i + 1), 4);

        if (i + 1 >= order) xh = right('0000' + (i + 1 + 1), 4);

        if (ds.getString(i, "id") == id) xh = right('0000' + (order), 4);
        ds.setValue(i, "info2", xh);

    }

    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65488223993213e6a7b24f01
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 14:05:24.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select id , info2  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    var ret = [];
    for (var i = 0; i < n; i++) {
        var xh = right('0000' + (i + 1), 4);

        if (i + 1 >= order) xh = right('0000' + (i + 1 + 1), 4);

        if (ds.getString(i, "id") == id) xh = right('0000' + (order), 4);
        ds.setValue(i, "info2", xh);
        println( i+"  "+  xh)  ;

    }

    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65488223993213e6a7b24f07
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 14:08:29.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select id , info2  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    var ret = [];
    for (var i = 0; i < n; i++) {
        var xh = right('0000' + (i + 1), 4);

        if (i + 1 >= order) xh = right('0000' + (i + 1 + 1), 4);

        if (ds.getString(i, "id") == id) 
        {
            println("found old xh= "+ ( i+1));
            xh = right('0000' + (order), 4);
        }
        ds.setValue(i, "info2", xh);
        println( i+"  "+  xh)  ;

    }

    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65488223993213e6a7b24f0d
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 14:10:00.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select id , info2  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    var ret = [];
    for (var i = 0; i < n; i++) {
        var xh = right('0000' + (i + 1), 4);

        if (i + 1 >= order) xh = right('0000' + (i + 1 + 1), 4);

        if (ds.getString(i, "id") == id) 
        {
            println("found old xh= "+ ( i+1));
            xh = right('0000' + (order), 4);
        }
        ds.setValue(i, "info2", xh);
        println( (i+1)+"  "+  xh)  ;

    }

    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65488223993213e6a7b24f13
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 14:10:17.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select *  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    var ret = [];
    for (var i = 0; i < n; i++) {
        var xh = right('0000' + (i + 1), 4);

        if (i + 1 >= order) xh = right('0000' + (i + 1 + 1), 4);

        if (ds.getString(i, "id") == id) 
        {
            println("found old xh= "+ ( i+1));
            xh = right('0000' + (order), 4);
        }
        ds.setValue(i, "info2", xh);
        println( (i+1)+"  "+  xh)  ;

    }

    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65488223993213e6a7b24f18
scriptid: 60c4bd735db2478f9c5a111c
tablename: app_template
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 14:14:48.000
script:
var pzh_prefix;
var pzh_length;

var fullScreenDiv = null;



function formOpen() {
    book.showTabOnWhere = 'none';
    //加载帐套信息及年月
    var corpid = book.sheet0.cells("corpid").getValueString();
    runTask("当前记帐期", { corpid: corpid }, function (ym) {
        if (ym == null || ym == 'null') return;
        //得到年月后，获取凭证号相关设置
        pzh_len = getPZHLen(corpid);

        book.sheet0.cells("ym").setValue(ym);

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);


    });

    book.sheet2.getBrick('FJ').selectionMode = 'multi'; //图片设置成多选模式


    // 追加一些CSS类 ，用于凭证号标记
    $(document.body).append(`<style>
                        .pzh {position:absolute;left:0;bottom:0px; 
                                height:24px; line-height:24px;width:100%; 
                                background-color:#40af40a0; 
                                color:white;font-weight:bold;font-size:12px;text-align:center;}
                        .delete_pzh { position:absolute; right:0; width:40px; height:14px; top:0; text-align:right; 
                                    vertical-align:top; font-size:12px; color:gray;padding-right:5px;}      
                        .delete_pzh:hover { color:white;}      
                          
                        </style>
                    `);


}

function cb_check_onClick() {
    smartRetrieve(book.sheet0, "pzh_check", true, false, function () { //检索完后回调
        if ($pzh_check_ds.rowCount == 0) {
            toastr.success("凭证号检测通过");

        } else {
            book.sheet3.popup('fa fa-cog', '缺失的凭证', 250, 350, true, true, {});
        }
    });
}


/**
 * 多行结果集当前焦点行发生变化
 * @param dsname  结果集名称
 * @param row  行号
 */
//@comment (group=单元格事件,caption=单元格行焦点发生变化)
function currentBindRowChanged(dsname, row) {
    if (dsname == 'dzpz_pz') {
        //重新加载凭证图片列表

        let id = $dzpz_pz_ds.getString(row, "id");
        let pzh = $dzpz_pz_ds.getString(row, "pzh");
        loadPZ(pzh, id);

    }
}

function viewPDF(id) {
    var url = get_PZ_PDF_URL(id);
    openWindow(url);
}

/**
 * 单元格的值发生了改变
 * @param sheet  所在的工作表
 * @param cell  单元格对象
 * @param oldValue  原先的值
 * @param newValue 变化后的值
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChanged(sheet, cell, oldValue, newValue, innerRow) {

    //如果是绑定了数据库的，强烈不建议使用本事件，换用结果集变化事件 itemChanged

    //通过别名来判断
    if (cell.alias == 'ym') {
        var corpid = book.sheet0.cells("corpid").getValueString();
        var ym = book.sheet0.cells("ym").getValue();

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);
    }




}

function loadPZ(pzh, id) {

    let data = getPZFJ(id); //得到凭证的所有图片
    let FJ = book.sheet2.getBrick('FJ');
    FJ.buildGridly(data, function () {
        let shortPZH = pzh;//.substring(pzh_prefix.length);
        //加载图片完成后， 如果是凭证，那么加上凭证号信息
        for (let i = 0; i < data.length; i++) {
            if (data[i].groupname == '凭证') {
                setPZH(data[i].id, shortPZH, false);
            }
        }




    });
    g_selectedAll = false; //加载一个凭证的图片后 ，默认是不全选中的
    book.sheet2.yOffset = 0; //垂直卷滚条归位
}


//@comment (group=凭证号,caption=设置图片的凭证号,needRightControl=false)
function setPZH(id, pzh, needDeleteButton) {
    if (needDeleteButton == undefined) needDeleteButton = true
    find_pzh(id, true, needDeleteButton).find('.no').text(pzh);
}

//@comment (group=凭证号,caption=查找或创建凭证号标记对象,needRightControl=false)
function find_pzh(id, create_if_not_exists, needDeleteButton) {

    if (needDeleteButton == undefined) needDeleteButton = true;

    var d = $('#' + id);
    if (!d) {
        $.alert(id + "不存在");
        return null;
    }

    var ret = d.find('.pzh');
    if (ret.length == 0) {
        if (create_if_not_exists) //如果需要创建，则创建它
        {
            d.append(`<div class="pzh" >
                        <div class="no"></div>
                        <div class="delete_pzh"  ${needDeleteButton ? "" : " style='display:none' "} ><i class="fa fa-close" onclick="removePZH('${id}');  event.preventDefault(); event.stopPropagation();"> </i></div>
                      </div>`);
        }
        ret = d.find('.pzh');
    }
    return ret;

}



/**
 * 单元格单击事件
 * @param sheet
 * @param cell
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行被点击
 * @param event 事件对象
 */
//@comment (group=单元格事件,caption=单元格点击)
function cellOnClick(sheet, cell, innerRow, event) {

    //通过别名来判断
    if (cell.alias == 'XXX') {

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'dzpz_pz') {
        if (bind.DBCol == 'c_sh1') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") != 0) return; //已审核，不要再审核
            do_sh1(innerRow, function () {
                if (innerRow < $dzpz_pz_ds.rowCount - 1) {
                    book.getDataSource('dzpz_pz').currentBindRow = innerRow + 1;
                }
            });
        }
        if (bind.DBCol == 'c_sh2') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") == 0) return; //没有审核，不需要取消审核
            do_sh2(innerRow);
        }
    }

}

function do_sh1(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    let pzh = $dzpz_pz_ds.getString(innerRow, "pzh");

    do_sh(id, true, function (ret)  //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", ret.verifierid);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", ret.verifiername);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", ret.verifieddate);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "校对成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "取消校对");

        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}

function do_sh2(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    do_sh(id, false, function (ret) //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", null);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", null);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", null);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "取消成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "校对");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "");


        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}



//@comment (group=工具函数,caption=全选或取消全选)
function seletOrUnSelectAll() {
    //让selection单元格失去编辑焦点，不然再点击，它不会触发单元格的点击事件，因为此时点击的编辑框对象，不会触发单元格的点击
    book.sheet1.View.forceCurrentEditControlGiveUpFocus();

    var v = book.sheet1.cells('selection').getValueInt();

    book.sheet1.paintPermit = false;
    $dzpz_pz_ds.setValueWithTrigger = false;
    for (var i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        $dzpz_pz_ds.setValue(i, "selected", v);
    }
    $dzpz_pz_ds.setValueWithTrigger = true;
    book.sheet1.paintPermit = true;
}


function cb_verify_onClick() {
    $confirm('', '确信要对选中的凭证做审核确认吗?', function () {
        let rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在审核确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在校对确认 " + i);
                do_sh1(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("校对完成");
        });

    });
}



function cb_unverify_onClick() {

    $confirm('', '确信要对选中的凭证做取消校对吗?', function () {
        var rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在取消确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在取消确认" + i);
                do_sh2(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("取消确认完成");
        });

    });


}


function cb_package_onClick() {

    let ids = [];
    for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
        ids.push($dzpz_pz_ds.getString(i, "id"));
    }

    if (ids.length == 0) {
        toastr.info("至少选中一张凭证");
        return;
    }

    $confirm('', '确信要将选中的凭证打包下载吗?', function () {
        showInfoPane("*正在压缩打包...");
        runTask("打包下载", { fileName: formatDate(newDate(), "yyyyMMddHHmm") + ".zip", ids: ids },
            function (ret) {
                ret = JSON.parse(ret);
                hideInfoPane();
                if (ret.success) {
                    openWindow(ret.url);
                } else {
                    toastr.error(ret.message);
                }
            });

    });
}

function isVerified() {
    var row = book.getDataSource('dzpz_pz').currentBindRow;
    var verifiername = $dzpz_pz_ds.getString(row, "verifiername");

    if (verifiername != '') {
        toastr.error("已经校对的凭证不允许执行此操作");
        return true;
    }
    return false;
}


/**
 * 图片控件初始化完成
 * @param sheet   所在Sheet
 * @param config  图片控件的名称
 *@param data  该图片的详细信息
 *
 */
//@comment (group=图片控件,caption=图片控件初始化完成)
function imageGridlyInited(sheet, name, data) {


    if (name == "FJ") {
        //图片都初始化后， 定制右上角的工具栏，最多可加5个工具按 钮
        let brick = sheet.getBrick(name);

        brick.addToolButton(1  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-repeat",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '90', function () { hideInfoPane(); });

            }
        );


        brick.addToolButton(2  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-eye",   // 字符图标
            "浏览大图",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                brick.popupShow(id);

            }
        );


        brick.addToolButton(3  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-sort",   // 字符图标
            "设置顺序",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                setImgOrder(id);

            }
        );



        brick.addToolButton(4  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-rotate-left",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '270', function () { hideInfoPane(); });

            }
        );



    }
}


function rotateImg(sheet, id, degree, callback) {



    let brick = sheet.getBrick('FJ');
    setTimeout(function () {
        //toastr.info(id);  // id 是当前操作的图片对应数据的ID

        do_imageRotate(id, degree, function (ret) {


            if (ret.success) {

                g_turningCount++;
                showInfoPane('*正在旋转图片' + g_turningCount + "/" + g_turnNeedCount + ' ...');


                //把数据中的图片替换，
                for (let i = 0; i < brick.data.length; i++) {
                    if (brick.data[i].id == id) {
                        //属性从新的属性中替换 
                        for (let prop in brick.data[i]) {
                            brick.data[i][prop] = ret.data[prop];
                        }
                        break;
                    }
                }
                //把缩略图的图片地址替换 ， 

                let img = $('#' + id).find('.image');
                img.attr("src", ret.data.url_thumbnail);
                img.attr('largeimage', ret.data.url_img);
                //把大图预览的地址替换掉
                //book.sheet0.cells("imgPreview").setValue(ret.data.url_img);

            }
            if (callback) callback();



        });
    }, 100);

}


function setImgOrder(id) {
    inputBox("调整顺序", "输入本图片的序号", "", "图片顺序号", function (v) {
        if (isNaN(v)) {
            toastr.error("请输入一个数字表示图片的序号");
            return;
        }
        v = parseInt(v);

        let row = book.getDataSource('dzpz_pz').currentBindRow;
        let gguid = $dzpz_pz_ds.getString(row, "id");
        let pzh = $dzpz_pz_ds.getString(row, "pzh");
        back_setImageOrder(gguid, id, v, function () {
 

            loadPZ(pzh, gguid);
        });

    }, false);
}
/**
 * 图片控件中的图片控件顺序发生变化
 * @param sheet   所在Sheet
 * @param name  图片控件的名称
 *@param  ids  当前顺序下的图片的ID数组
 *
 *
 *
 */
//@comment (group=图片控件,caption=图片顺序被改变)
function imageOrderChanged(sheet, name, ids) {

    if (isVerified()) return;  //校对过的不允许再调整顺序

    reOrderImage(ids, function (ret) { }); //放一个空的回调函数让它异步执行，不卡界面

}


var g_selectedAll = false;
function cb_selectallimg_onClick() { g_selectedAll = !g_selectedAll; doSelect(g_selectedAll); }


function doSelect(b) {
    var imgPool = book.sheet2.getBrick('FJ');
    if (b) {
        imgPool.selectAll();
    } else {
        imgPool.unSelectAll();
    }
}


function cb_turnLeft_onClick() {
    turnSelection('270');

}

function cb_turnRight_onClick() {

    turnSelection('90');
}

var g_turningCount = 0;
var g_turnedCount = 0;

function turnSelection(degree) {

    if (isVerified()) return;  //校对过的不允许再旋转

    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    // 当前选中的
    var selection = imgPool.getSelectedImageList();
    if (selection.length == 0) {
        toastr.error("至少选中一张图片");
        return;
    }


    $confirm("提示", "确信要对选中的" + selection.length + "张图片做旋转吗?", function () {

        g_turningCount = 0;
        g_turnedCount = 0;
        g_turnNeedCount = selection.length;
        /*
                setTimeout(function () {
                    for (var i = 0; i < selection.length; i++) {
                        rotateImg(sheet, selection[i].id, degree, i * 1000);
                    }
                }, 10);
                */

        asyncPool(4, selection, function (item, array) {
            return new Promise(function (resolve, reject) {

                console.dir(item);
                rotateImg(sheet, item.id, degree,
                    function () { //注意，在旋转完成后，再设置resolve 表示本任务已完成，而不是直接就resolve ,不然最后的 then 执行时机不对，这么处理，就会在全部旋转完成后，再执行then中的脚本，而不是旋转任务全部发起后就执行 then 
                        resolve(item)
                    });

            });
        }).then(function () {

            setTimeout(function () {

                hideInfoPane();
                toastr.info("旋转完成");
            }, 500);
        });

    });

}




function test1() {


    asyncPool(3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (item, array) {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                console.info(item + "   " + new Date());
                resolve(item)
            }, 1000);

        });
    }).then(function () {
        console.info("over");
    });

}



function ocrTest() {
    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    let imgs = imgPool.getCurrentSortedImageList();//得到当前排序后的图片清单
    let one = imgs[0];

    runTask("pzh-ocr", { src: one.url_img, left: '35%', top: '8%', height: '8%', width: '50%' }, function (text) {
        toastr.info(text);
    });

}


id: 65488223993213e6a7b24f27
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 14:23:38.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select *  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    var ret = [];
    for (var i = 0; i < n; i++) {
        var xh = i+1;

        if ( xh >= order) xh = xh +1 ;

        if (ds.getString(i, "id") == id) 
        {
            println("found old xh= "+ ( i+1));
            xh =  order  ;
        }
        xh = right('0000' + xh, 4);
        ds.setValue(i, "info2", xh);
        println( (i+1)+"  "+  xh)  ;

    }

    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65488223993213e6a7b24f2e
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 15:03:54.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select *  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);


    var old_xh =0;
    for (var i = 0; i < n; i++) {
        
        if (ds.getString(i, "id") == id) 
        {
            
             old_xh= i +1 ; 
             break; 
        } 
    }

    var delta =  0; 
    if( old_xh <  order)  delta =1; 
    var ret = [];
    for (var i = 0; i < n; i++) {
        var xh = i+1;

        if ( xh >= old_v && xh <= order) xh = xh  - 1 ;
         

        if (ds.getString(i, "id") == id) 
        {
            println("found old xh= "+ ( i+1));
            xh =  order  ;
        }
        xh = right('0000' + xh, 4);
        ds.setValue(i, "info2", xh);
        println( (i+1)+"  "+  xh)  ;

    }

    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65488223993213e6a7b24f36
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 15:15:40.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select *  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);


    var old_xh = 0;
    for (var i = 0; i < n; i++) {

        var xh = right('0000' + (i + 1), 4);
        ds.setValue(i, "info2", xh);

        if (ds.getString(i, "id") == id) {

            old_xh = i + 1;
            xh = right('0000' + order, 4);
            ds.setValue(i, "info2", xh);
        }
    }

    if (order > old_xh) {
        for (var i = old_xh; i < order; i++) {
            var xh = right('0000' + (i), 4);
            ds.setValue(i, "info2", xh);
        }

    } else {
        for (var i = order; i < old_xh; i++) {
            var xh = right('0000' + (i + 1), 4);
            ds.setValue(i, "info2", xh);
        }
    }




    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65488223993213e6a7b24f3d
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 15:18:01.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select *  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    if( order>n)  order=n; 
    
    var old_xh = 0;
    for (var i = 0; i < n; i++) {

        var xh = right('0000' + (i + 1), 4);
        ds.setValue(i, "info2", xh);

        if (ds.getString(i, "id") == id) {

            old_xh = i + 1;
            xh = right('0000' + order, 4);
            ds.setValue(i, "info2", xh);
        }
    }

    if (order > old_xh) {
        for (var i = old_xh; i < order; i++) {
            var xh = right('0000' + (i), 4);
            ds.setValue(i, "info2", xh);
        }

    } else {
        for (var i = order; i < old_xh; i++) {
            var xh = right('0000' + (i + 1), 4);
            ds.setValue(i, "info2", xh);
        }
    }




    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65488223993213e6a7b24f43
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.192.37.128
username: sa
createdate: 2023.11.06 15:19:37.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select *  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    if( order>n)  order=n; 

    var old_xh = 0;
    for (var i = 0; i < n; i++) {

        var xh = right('0000' + (i + 1), 4);
        ds.setValue(i, "info2", xh);

        if (ds.getString(i, "id") == id) {

            old_xh = i + 1;
            xh = right('0000' + order, 4);
            ds.setValue(i, "info2", xh);
            println( "set   "+ i+" row , xh="+ xh );
        }
    }

    if (order > old_xh) {
        for (var i = old_xh; i < order; i++) {
            var xh = right('0000' + (i), 4);
            ds.setValue(i, "info2", xh);
            println( "change  "+ i+" row , xh="+ xh );
        }

    } else {
        for (var i = order; i < old_xh; i++) {
            var xh = right('0000' + (i + 1), 4);
            ds.setValue(i, "info2", xh);
            println( "change  "+ i+" row , xh="+ xh );
        }
    }




    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 65488223993213e6a7b24f49
scriptid: 60c4bd735db2478f9c5a111c
tablename: app_template
clientip: 115.227.98.87
username: sa
createdate: 2023.11.08 13:23:05.000
script:
var pzh_prefix;
var pzh_length;

var fullScreenDiv = null;



function formOpen() {
    book.showTabOnWhere = 'none';
    //加载帐套信息及年月
    var corpid = book.sheet0.cells("corpid").getValueString();
    runTask("当前记帐期", { corpid: corpid }, function (ym) {
        if (ym == null || ym == 'null') return;
        //得到年月后，获取凭证号相关设置
        pzh_len = getPZHLen(corpid);

        book.sheet0.cells("ym").setValue(ym);

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);


    });

    book.sheet2.getBrick('FJ').selectionMode = 'multi'; //图片设置成多选模式


    // 追加一些CSS类 ，用于凭证号标记
    $(document.body).append(`<style>
                        .pzh {position:absolute;left:0;bottom:0px; 
                                height:24px; line-height:24px;width:100%; 
                                background-color:#40af40a0; 
                                color:white;font-weight:bold;font-size:12px;text-align:center;}
                        .delete_pzh { position:absolute; right:0; width:40px; height:14px; top:0; text-align:right; 
                                    vertical-align:top; font-size:12px; color:gray;padding-right:5px;}      
                        .delete_pzh:hover { color:white;}      
                          
                        </style>
                    `);


}

function cb_check_onClick() {
    smartRetrieve(book.sheet0, "pzh_check", true, false, function () { //检索完后回调
        if ($pzh_check_ds.rowCount == 0) {
            toastr.success("凭证号检测通过");

        } else {
            book.sheet3.popup('fa fa-cog', '缺失的凭证', 250, 350, true, true, {});
        }
    });
}


/**
 * 多行结果集当前焦点行发生变化
 * @param dsname  结果集名称
 * @param row  行号
 */
//@comment (group=单元格事件,caption=单元格行焦点发生变化)
function currentBindRowChanged(dsname, row) {
    if (dsname == 'dzpz_pz') {
        //重新加载凭证图片列表

        let id = $dzpz_pz_ds.getString(row, "id");
        let pzh = $dzpz_pz_ds.getString(row, "pzh");
        loadPZ(pzh, id);

    }
}

function viewPDF(id) {
    var url = get_PZ_PDF_URL(id);
    openWindow(url);
}

/**
 * 单元格的值发生了改变
 * @param sheet  所在的工作表
 * @param cell  单元格对象
 * @param oldValue  原先的值
 * @param newValue 变化后的值
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChanged(sheet, cell, oldValue, newValue, innerRow) {

    //如果是绑定了数据库的，强烈不建议使用本事件，换用结果集变化事件 itemChanged

    //通过别名来判断
    if (cell.alias == 'ym') {
        var corpid = book.sheet0.cells("corpid").getValueString();
        var ym = book.sheet0.cells("ym").getValue();

        pzh_prefix = getPZHPrefix(corpid, ym);
        book.sheet0.cells("pzh_prefix").setValue(pzh_prefix);
    }




}

function loadPZ(pzh, id) {

    let data = getPZFJ(id); //得到凭证的所有图片
    let FJ = book.sheet2.getBrick('FJ');
    FJ.buildGridly(data, function () {
        let shortPZH = pzh;//.substring(pzh_prefix.length);
        //加载图片完成后， 如果是凭证，那么加上凭证号信息
        for (let i = 0; i < data.length; i++) {
            if (data[i].groupname == '凭证') {
                setPZH(data[i].id, shortPZH, false);
            }
        }




    });
    g_selectedAll = false; //加载一个凭证的图片后 ，默认是不全选中的
    book.sheet2.yOffset = 0; //垂直卷滚条归位
}


//@comment (group=凭证号,caption=设置图片的凭证号,needRightControl=false)
function setPZH(id, pzh, needDeleteButton) {
    if (needDeleteButton == undefined) needDeleteButton = true
    find_pzh(id, true, needDeleteButton).find('.no').text(pzh);
}

//@comment (group=凭证号,caption=查找或创建凭证号标记对象,needRightControl=false)
function find_pzh(id, create_if_not_exists, needDeleteButton) {

    if (needDeleteButton == undefined) needDeleteButton = true;

    var d = $('#' + id);
    if (!d) {
        $.alert(id + "不存在");
        return null;
    }

    var ret = d.find('.pzh');
    if (ret.length == 0) {
        if (create_if_not_exists) //如果需要创建，则创建它
        {
            d.append(`<div class="pzh" >
                        <div class="no"></div>
                        <div class="delete_pzh"  ${needDeleteButton ? "" : " style='display:none' "} ><i class="fa fa-close" onclick="removePZH('${id}');  event.preventDefault(); event.stopPropagation();"> </i></div>
                      </div>`);
        }
        ret = d.find('.pzh');
    }
    return ret;

}



/**
 * 单元格单击事件
 * @param sheet
 * @param cell
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行被点击
 * @param event 事件对象
 */
//@comment (group=单元格事件,caption=单元格点击)
function cellOnClick(sheet, cell, innerRow, event) {

    //通过别名来判断
    if (cell.alias == 'XXX') {

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'dzpz_pz') {
        if (bind.DBCol == 'c_sh1') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") != 0) return; //已审核，不要再审核
            do_sh1(innerRow, function () {
                if (innerRow < $dzpz_pz_ds.rowCount - 1) {
                    book.getDataSource('dzpz_pz').currentBindRow = innerRow + 1;
                }
            });
        }
        if (bind.DBCol == 'c_sh2') {
            if ($dzpz_pz_ds.getInt(innerRow, "verifierid") == 0) return; //没有审核，不需要取消审核
            do_sh2(innerRow);
        }
    }

}

function do_sh1(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    let pzh = $dzpz_pz_ds.getString(innerRow, "pzh");

    do_sh(id, true, function (ret)  //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", ret.verifierid);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", ret.verifiername);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", ret.verifieddate);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "校对成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "取消校对");

        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}

function do_sh2(innerRow, callback) {
    let id = $dzpz_pz_ds.getString(innerRow, "id");
    do_sh(id, false, function (ret) //后台执行
    {
        if (ret.success) {
            $dzpz_pz_ds.setValue(innerRow, "verifierid", null);
            $dzpz_pz_ds.setValue(innerRow, "verifiername", null);
            $dzpz_pz_ds.setValue(innerRow, "verifieddate", null);
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", "取消成功");
            $dzpz_pz_ds.setValue(innerRow, "c_sh1", "校对");
            $dzpz_pz_ds.setValue(innerRow, "c_sh2", "");


        } else {
            $dzpz_pz_ds.setValue(innerRow, "tipinfo", ret.message);

        }
        if (callback) callback();
    });
}



//@comment (group=工具函数,caption=全选或取消全选)
function seletOrUnSelectAll() {
    //让selection单元格失去编辑焦点，不然再点击，它不会触发单元格的点击事件，因为此时点击的编辑框对象，不会触发单元格的点击
    book.sheet1.View.forceCurrentEditControlGiveUpFocus();

    var v = book.sheet1.cells('selection').getValueInt();

    book.sheet1.paintPermit = false;
    $dzpz_pz_ds.setValueWithTrigger = false;
    for (var i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        $dzpz_pz_ds.setValue(i, "selected", v);
    }
    $dzpz_pz_ds.setValueWithTrigger = true;
    book.sheet1.paintPermit = true;
}


function cb_verify_onClick() {
    $confirm('', '确信要对选中的凭证做审核确认吗?', function () {
        let rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在审核确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在校对确认 " + i);
                do_sh1(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("校对完成");
        });

    });
}



function cb_unverify_onClick() {

    $confirm('', '确信要对选中的凭证做取消校对吗?', function () {
        var rows = [];
        for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
            if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
            rows.push(i);
        };

        showInfoPane("* 正在取消确认...");
        asyncPool(4, rows, function (i, rows) {
            return new Promise(function (resolve, reject) {
                showInfoPane("* 正在取消确认" + i);
                do_sh2(i, function () {
                    resolve(i);
                });
            });
        }).then(function (v) {
            hideInfoPane();
            toastr.info("取消确认完成");
        });

    });


}


function cb_package_onClick() {

    let ids = [];
    for (let i = 0; i < $dzpz_pz_ds.rowCount; i++) {
        if ($dzpz_pz_ds.getInt(i, "selected") == 0) continue;
        ids.push($dzpz_pz_ds.getString(i, "id"));
    }

    if (ids.length == 0) {
        toastr.info("至少选中一张凭证");
        return;
    }

    $confirm('', '确信要将选中的凭证打包下载吗?', function () {
        showInfoPane("*正在压缩打包...");
        runTask("打包下载", { fileName: formatDate(newDate(), "yyyyMMddHHmm") + ".zip", ids: ids },
            function (ret) {
                ret = JSON.parse(ret);
                hideInfoPane();
                if (ret.success) {
                    openWindow(ret.url);
                } else {
                    toastr.error(ret.message);
                }
            });

    });
}

function isVerified() {
    var row = book.getDataSource('dzpz_pz').currentBindRow;
    var verifiername = $dzpz_pz_ds.getString(row, "verifiername");

    if (verifiername != '') {
        toastr.error("已经校对的凭证不允许执行此操作");
        return true;
    }
    return false;
}


/**
 * 图片控件初始化完成
 * @param sheet   所在Sheet
 * @param config  图片控件的名称
 *@param data  该图片的详细信息
 *
 */
//@comment (group=图片控件,caption=图片控件初始化完成)
function imageGridlyInited(sheet, name, data) {


    if (name == "FJ") {
        //图片都初始化后， 定制右上角的工具栏，最多可加5个工具按 钮
        let brick = sheet.getBrick(name);

        brick.addToolButton(1  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-repeat",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '90', function () { hideInfoPane(); });

            }
        );


        brick.addToolButton(2  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-eye",   // 字符图标
            "浏览大图",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                brick.popupShow(id);

            }
        );


        brick.addToolButton(3  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-sort-numeric-asc",   // 字符图标
            "设置顺序",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                setImgOrder(id);

            }
        );



        brick.addToolButton(4  //在从右往左数第2个工作栏位置添加一个工具按钮
            , "fa-rotate-left",   // 字符图标
            "旋转图片",  // 鼠标悬停的提示信息
            "green", //按钮背景色
            function (id) {  //点击后的回调函数
                g_turningCount = 0;
                g_turnedCount = 0;
                g_turnNeedCount = 1;
                if (isVerified()) return;  //校对过的不允许再旋转

                rotateImg(sheet, id, '270', function () { hideInfoPane(); });

            }
        );



    }
}


function rotateImg(sheet, id, degree, callback) {



    let brick = sheet.getBrick('FJ');
    setTimeout(function () {
        //toastr.info(id);  // id 是当前操作的图片对应数据的ID

        do_imageRotate(id, degree, function (ret) {


            if (ret.success) {

                g_turningCount++;
                showInfoPane('*正在旋转图片' + g_turningCount + "/" + g_turnNeedCount + ' ...');


                //把数据中的图片替换，
                for (let i = 0; i < brick.data.length; i++) {
                    if (brick.data[i].id == id) {
                        //属性从新的属性中替换 
                        for (let prop in brick.data[i]) {
                            brick.data[i][prop] = ret.data[prop];
                        }
                        break;
                    }
                }
                //把缩略图的图片地址替换 ， 

                let img = $('#' + id).find('.image');
                img.attr("src", ret.data.url_thumbnail);
                img.attr('largeimage', ret.data.url_img);
                //把大图预览的地址替换掉
                //book.sheet0.cells("imgPreview").setValue(ret.data.url_img);

            }
            if (callback) callback();



        });
    }, 100);

}


function setImgOrder(id) {
    inputBox("调整顺序", "输入本图片的序号", "", "图片顺序号", function (v) {
        if (isNaN(v)) {
            toastr.error("请输入一个数字表示图片的序号");
            return;
        }
        v = parseInt(v);

        let row = book.getDataSource('dzpz_pz').currentBindRow;
        let gguid = $dzpz_pz_ds.getString(row, "id");
        let pzh = $dzpz_pz_ds.getString(row, "pzh");
        back_setImageOrder(gguid, id, v, function () {

            setTimeout(function () {
                loadPZ(pzh, gguid);
            }, 500);
        });

    }, false);
}
/**
 * 图片控件中的图片控件顺序发生变化
 * @param sheet   所在Sheet
 * @param name  图片控件的名称
 *@param  ids  当前顺序下的图片的ID数组
 *
 *
 *
 */
//@comment (group=图片控件,caption=图片顺序被改变)
function imageOrderChanged(sheet, name, ids) {

    if (isVerified()) return;  //校对过的不允许再调整顺序

    reOrderImage(ids, function (ret) { }); //放一个空的回调函数让它异步执行，不卡界面

}


var g_selectedAll = false;
function cb_selectallimg_onClick() { g_selectedAll = !g_selectedAll; doSelect(g_selectedAll); }


function doSelect(b) {
    var imgPool = book.sheet2.getBrick('FJ');
    if (b) {
        imgPool.selectAll();
    } else {
        imgPool.unSelectAll();
    }
}


function cb_turnLeft_onClick() {
    turnSelection('270');

}

function cb_turnRight_onClick() {

    turnSelection('90');
}

var g_turningCount = 0;
var g_turnedCount = 0;

function turnSelection(degree) {

    if (isVerified()) return;  //校对过的不允许再旋转

    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    // 当前选中的
    var selection = imgPool.getSelectedImageList();
    if (selection.length == 0) {
        toastr.error("至少选中一张图片");
        return;
    }


    $confirm("提示", "确信要对选中的" + selection.length + "张图片做旋转吗?", function () {

        g_turningCount = 0;
        g_turnedCount = 0;
        g_turnNeedCount = selection.length;
        /*
                setTimeout(function () {
                    for (var i = 0; i < selection.length; i++) {
                        rotateImg(sheet, selection[i].id, degree, i * 1000);
                    }
                }, 10);
                */

        asyncPool(4, selection, function (item, array) {
            return new Promise(function (resolve, reject) {

                console.dir(item);
                rotateImg(sheet, item.id, degree,
                    function () { //注意，在旋转完成后，再设置resolve 表示本任务已完成，而不是直接就resolve ,不然最后的 then 执行时机不对，这么处理，就会在全部旋转完成后，再执行then中的脚本，而不是旋转任务全部发起后就执行 then 
                        resolve(item)
                    });

            });
        }).then(function () {

            setTimeout(function () {

                hideInfoPane();
                toastr.info("旋转完成");
            }, 500);
        });

    });

}




function test1() {


    asyncPool(3, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (item, array) {
        return new Promise(function (resolve, reject) {
            setTimeout(function () {
                console.info(item + "   " + new Date());
                resolve(item)
            }, 1000);

        });
    }).then(function () {
        console.info("over");
    });

}



function ocrTest() {
    var sheet = book.sheet2;
    var imgPool = sheet.getBrick('FJ');
    let imgs = imgPool.getCurrentSortedImageList();//得到当前排序后的图片清单
    let one = imgs[0];

    runTask("pzh-ocr", { src: one.url_img, left: '35%', top: '8%', height: '8%', width: '50%' }, function (text) {
        toastr.info(text);
    });

}


id: 65488223993213e6a7b24f52
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 115.227.98.87
username: sa
createdate: 2023.11.08 13:26:36.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select *  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    if( order>n)  order=n; 

    var old_xh = 0;
    for (var i = 0; i < n; i++) {

        var xh = right('0000' + (i + 1), 4);
        ds.setValue(i, "info2", xh);

        if (ds.getString(i, "id") == id) {

            old_xh = i + 1;
            xh = right('0000' + order, 4);
            ds.setValue(i, "info2", xh);
            println( "set   "+ i+" row , xh="+ xh );
        }
    }

//往后调
// 则把在此图片之后的图片到新位置之前的图片的序号减1
    if (order > old_xh) {
        for (var i = old_xh; i < order; i++) {
            var xh = right('0000' + (i), 4);
            ds.setValue(i, "info2", xh);
            println( "change  "+ i+" row , xh="+ xh );
        }

    } else {
        //往前调，则把新位置之后的图片到当前图片序号之间的图片的序号加1 
        for (var i = order; i < old_xh; i++) {
            var xh = right('0000' + (i + 1), 4);
            ds.setValue(i, "info2", xh);
            println( "change  "+ i+" row , xh="+ xh );
        }
    }




    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 654c835b993213e6a7b24f66
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 39.170.92.207
username: sa
createdate: 2023.11.09 14:59:40.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select *  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    if( order>n)  order=n; 

    var old_xh = 0;
    for (var i = 0; i < n; i++) {

        var xh = right('0000' + (i + 1), 4);
        ds.setValue(i, "info2", xh);

        if (ds.getString(i, "id") == id) {

            old_xh = i + 1;
            xh = right('0000' + order, 4);
            ds.setValue(i, "info2", xh);
            println( "set   "+ i+" row , xh="+ xh );
        }
    }

//往后调
// 则把在此图片之后的图片到新位置之前的图片的序号减1
    if (order > old_xh) {
        for (var i = old_xh; i < order; i++) {
            var xh = right('0000' + (i), 4);
            ds.setValue(i, "info2", xh);
            println( "change  "+ i+" row , xh="+ xh );
        }

    } else {
        //往前调，则把新位置之后的图片到当前图片序号之间的图片的序号加1 
        for (var row = order -1    ; row < old_xh -1 ; row++) {
            var i= row+1; 
            var xh = right('0000' + (i + 1), 4);
            ds.setValue(row, "info2", xh);
            println( "change  "+ row +" row , xh="+ xh );
        }
    }




    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 654c835b993213e6a7b24f6c
scriptid: 60c4bd735db2478f9c5a1118
tablename: app_script
clientip: 39.170.92.207
username: sa
createdate: 2023.11.09 15:00:18.000
script:
//@comment (group=,caption=构建凭证附件清单,needRightControl=false)
function getPZFJ(id) {
    var ds = newDataStore("", "select id ,   url_img , url_thumbnail ,groupname , info1 from  dzpz_pzfj where  gguid='" + id + "'  order by info2 asc, groupname ,  info1 asc ");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());

    var ret = [];
    for (var i = 0; i < n; i++) {

        var one = JSON.parse(ds.getJSONRow(i, true));
        one.url_img = one.url_img + "&imageForceWatermark=false"
        ret.push(one);

    }
    return ret;

}


function get_PZ_PDF_URL(id) {
    return getStringFromSQL("select url_img from app_archive where gguid='" + id + "'");
}

//单独设置某张图片的序号
function back_setImageOrder(gguid, id, order) {
    var ds = newDataStore("", `select *  from  dzpz_pzfj where  gguid='${gguid}' order by info2 asc, groupname ,info1 asc `);
    ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    var n = ds.retrieve();
    println(ds.getSelectLastRetrieved());
    println(n);

    if( order>n)  order=n; 

    var old_xh = 0;
    for (var i = 0; i < n; i++) {

        var xh = right('0000' + (i + 1), 4);
        ds.setValue(i, "info2", xh);

        if (ds.getString(i, "id") == id) {

            old_xh = i + 1;
            xh = right('0000' + order, 4);
            ds.setValue(i, "info2", xh);
            println( "set   "+ i+" row , xh="+ xh );
        }
    }

//往后调
// 则把在此图片之后的图片到新位置之前的图片的序号减1
    if (order > old_xh) {
        for (var i = old_xh; i < order; i++) {
            var xh = right('0000' + (i), 4);
            ds.setValue(i, "info2", xh);
            println( "change  "+ i+" row , xh="+ xh );
        }

    } else {
        //往前调，则把新位置之后的图片到当前图片序号之间的图片的序号加1 
        //下面的 i , row  +1 , -1 是看着数据试验出来 的结果，不要凭空去想象
        for (var row = order -1    ; row < old_xh -1 ; row++) {
            var i= row+1; 
            var xh = right('0000' + (i + 1), 4);
            ds.setValue(row, "info2", xh);
            println( "change  "+ row +" row , xh="+ xh );
        }
    }




    if (!ds.update(true)) println(ds.getErrorMessage());
    return true;
}

function reOrderImage(ids) {
    var sqls = [];
    for (var i = 0; i < ids.length; i++) {
        var xh = right('0000' + (i + 1), 4);
        sqls.push("update dzpz_pzfj set info2 ='" + xh + "' where id='" + ids[i] + "' ");
    }
    runSQL("", sqls, true);
    println("调整顺序完成");

}


//@comment (group=,caption=凭证号前缀,needRightControl=false)
function getPZHPrefix(corpid, ym) {
    return runTask("getPZHPrefix", { corpid: corpid, ym: ym });

}
//@comment (group=,caption=凭证号长度,needRightControl=false)
function getPZHLen(corpid) {
    return parseInt(runTask("getPZHLen", { corpid: corpid }));
}



//@comment (group=,caption=凭证审核或取消审核,needRightControl=false)
function do_sh(id, sh) {


    //if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b697")) return { success: false, message: "没有审核权限" };



    var dzpz_ds = newDataStore("", "select * from dzpz_pz where id='" + id + "'");
    dzpz_ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    dzpz_ds.retrieve();
    if (dzpz_ds.getRowCount() == 0) {
        return { success: false, message: "凭证不存在" };
    }
    if (sh) //做审核
    {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        if (verifierid != 0) return {
            success: true, verifierid: verifierid,
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate"), message: "凭证已审核，不需要重复审核"
        };
        dzpz_ds.setValue(0, "verifierid", currentUserId());
        dzpz_ds.setValue(0, "verifiername", currentUserShowName());
        dzpz_ds.setValue(0, "verifieddate", newDate());

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };

        //审核后，归档
        runTask("pz_image2pdf", {
            id: id,
            overwrite: true  //如果已存在，删除并重新生成
        });

        return {
            success: true,
            verifierid: dzpz_ds.getString(0, "verifierid"),
            verifiername: dzpz_ds.getString(0, "verifiername"),
            verifieddate: dzpz_ds.getString(0, "verifieddate")
        };

    } else {
        var verifierid = dzpz_ds.getInt(0, "verifierid");
        println(verifierid);
        if (verifierid == 0) return { success: true, message: "凭证尚未审核，不需要取消审核" };
        if (verifierid != currentUserId()) {
            if (!isRoleGrantedToUser(currentUserId(), "60c81b135db2d209d074b6a7") && currentUserId() != 1) {

                return { success: false, message: "必须由审核人或超级审核员来取消审核" };
            }
        }
        dzpz_ds.setValue(0, "verifierid", null);
        dzpz_ds.setValue(0, "verifiername", null);
        dzpz_ds.setValue(0, "verifieddate", null);

        if (!dzpz_ds.update(true)) return { success: false, message: dzpz_ds.getError().getMessage() };
        return { success: true };
    }

}



//@comment (group=,caption=图片旋转,needRightControl=false)
function do_imageRotate(id, rt) {
    var ret = imageRotate("", "dzpz_pzfj", id, rt);
    println(JSON.stringify(ret));
    return ret;
}


id: 655b0bc29932b95f42145f0d
scriptid: 655b0a759932b95f42145ecd
tablename: app_script
clientip: 125.118.107.57
username: sa
createdate: 2023.11.20 15:33:44.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);

for( var i=0;i<10000;i++)
{
    println(`1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890`);
}

return 'ok' ; 


}


id: 6566d00b9932bfa1d16e4195
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 13:51:12.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid= $uploadpz_ds.getString(0,"corpid");
        let ym= $uploadpz_ds.getString(0,"ym");
        
        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (ret) {
                console.dir(ret);
                console.info(ret.url_img);
            },

            function (file, config) {
                console.dir(file);
                let name = file.name;
                if (name.endsWith('.pdf')) {
                    config.objectName = "aaaa.pdf";
                    return true;
                }
                toastr.error(name + "不是pdf， 禁止上传");

                return false;
            }
        );
    });
}


id: 6566d00b9932bfa1d16e41d9
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 14:16:32.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (ret) {
                console.dir(ret);
                console.info(ret.url_img);
            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (getStringFromSQL(`select id from  dzpz where corpid='${corpid}'  and ym= ${ym} and pzh='${pzh}' `) != '') {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6566d00b9932bfa1d16e41dd
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 14:41:02.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (data) {
                console.dir(data);
                console.info(data.url_img);
                let row = $uploadpzmx_ds.insertRow(99999);
                    let pzh= data.filename;
                    pzh= pzh.substring( pzh.lastIndexOf("/")+1 , pzh.lastIndexOf("."));
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 1);
                    $uploadpzmx_ds.setValue(row, "info", "成功上传");
                    
            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (getStringFromSQL(`select id from  dzpz where corpid='${corpid}'  and ym= ${ym} and pzh='${pzh}' `) != '') {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6566d00b9932bfa1d16e41e1
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 14:41:59.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (data) {
                console.dir(data);
                console.info(data.url_img);
                let row = $uploadpzmx_ds.insertRow(99999);
                    let pzh= data.filename;
                    pzh= pzh.substring( pzh.lastIndexOf("/")+1 , pzh.lastIndexOf("."));
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 1);
                    $uploadpzmx_ds.setValue(row, "info", "成功上传");
                    //创建凭证记录
                    create_pz(coprid, ym , pzh , data.url_img); 
            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (getStringFromSQL(`select id from  dzpz where corpid='${corpid}'  and ym= ${ym} and pzh='${pzh}' `) != '') {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6566e3fe9932bfa1d16e41ff
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:13:15.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (data) {
                console.dir(data);
                console.info(data.url_img);
                let row = $uploadpzmx_ds.insertRow(99999);
                    let pzh= data.filename;
                    pzh= pzh.substring( pzh.lastIndexOf("/")+1 , pzh.lastIndexOf("."));
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 1);
                    $uploadpzmx_ds.setValue(row, "info", "成功上传");
                    //创建凭证记录
                    create_pz(coprid, ym , pzh , data.id); 
            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (getStringFromSQL(`select id from  dzpz where corpid='${corpid}'  and ym= ${ym} and pzh='${pzh}' `) != '') {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6566e3fe9932bfa1d16e4208
scriptid: 655a1eb99932174d03378091
tablename: app_script
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:17:51.000
script:
function create_pz(coprid, ym, pzh, archive_id) {
    var ds = newDataStore("", "select  * from  dzpz_pz");
    ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    ds.insertRow(0);
    var newid = newGuid();
    ds.setValue(0, {
        id: newid,
        gguid: newid,
        billno: newid,
        billdate: newDate(),
        userid: currentUserId(),
        username: currentUserShowName(),
        corpid: corpid,
        ym: ym,
        pzh: pzh
    }
    );

    ds.executeAfterUpdate(` update  app_archive set gguid='${newid}'  where id='${archive_id}' `);
    if(  ds.update(true)) return ''
    return ds.getErrorMessage();

}


id: 6566e3fe9932bfa1d16e420e
scriptid: 655a1eb99932174d03378091
tablename: app_script
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:18:10.000
script:
function create_pz(coprid, ym, pzh, archive_id) {
    var ds = newDataStore("", "select  * from  dzpz_pz");
    ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    ds.insertRow(0);
    var newid = newGuid();
    ds.setValue(0, {
        id: newid,
        gguid: newid,
        billno: newid,
        billdate: newDate(),
        userid: currentUserId(),
        username: currentUserShowName(),
        corpid: corpid,
        ym: ym,
        pzh: pzh
    }
    );

    ds.executeAfterUpdate(` update  app_archive set gguid='${newid}'  where id='${archive_id}' `);
    if(  ds.update(true)) return '成功上传';
    return ds.getErrorMessage();

}


id: 6566e3fe9932bfa1d16e4214
scriptid: 655a1eb99932174d03378091
tablename: app_script
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:18:15.000
script:
function create_pz(coprid, ym, pzh, archive_id) {
    var ds = newDataStore("", "select  * from  dzpz_pz");
    ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    ds.insertRow(0);
    var newid = newGuid();
    ds.setValue(0, {
        id: newid,
        gguid: newid,
        billno: newid,
        billdate: newDate(),
        userid: currentUserId(),
        username: currentUserShowName(),
        corpid: corpid,
        ym: ym,
        pzh: pzh
    }
    );

    ds.executeAfterUpdate(` update  app_archive set gguid='${newid}'  where id='${archive_id}' `);
    if(  ds.update(true)) return '';
    return ds.getErrorMessage();

}


id: 6566e3fe9932bfa1d16e4218
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:20:52.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (data) {
                console.dir(data);
                console.info(data.url_img);
                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show( pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                let state = 0;
                create_pz(coprid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                });

            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (getStringFromSQL(`select id from  dzpz where corpid='${corpid}'  and ym= ${ym} and pzh='${pzh}' `) != '') {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6566e3fe9932bfa1d16e421c
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:22:04.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (data) {
                console.dir(data);
                console.info(data.url_img);
                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show( pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                let state = 0;
                create_pz(coprid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (getStringFromSQL(`select id from  dzpz where corpid='${corpid}'  and ym= ${ym} and pzh='${pzh}' `) != '') {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6566e3fe9932bfa1d16e4227
scriptid: 655a1eb99932174d03378091
tablename: app_script
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:36:36.000
script:
function create_pz(corpid, ym, pzh, archive_id) {
    var ds = newDataStore("", "select  * from  dzpz_pz");
    ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    ds.insertRow(0);
    var newid = newGuid();
    ds.setValue(0, {
        id: newid,
        gguid: newid,
        billno: newid,
        billdate: newDate(),
        userid: currentUserId(),
        username: currentUserShowName(),
        corpid: corpid,
        ym: ym,
        pzh: pzh
    }
    );

    ds.executeAfterUpdate(` update  app_archive set gguid='${newid}'  where id='${archive_id}' `);
    if(  ds.update(true)) return '';
    return ds.getErrorMessage();

}


id: 6566e3fe9932bfa1d16e422c
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:38:47.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if( ym==0)
        {
            toastr.error('请选择年，月');
            return;
        }

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (data) {
                console.dir(data);
                console.info(data.url_img);
                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show( pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                let state = 0;
                create_pz(coprid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (getStringFromSQL(`select id from  dzpz where corpid='${corpid}'  and ym= ${ym} and pzh='${pzh}' `) != '') {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6566e3fe9932bfa1d16e4230
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:40:13.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if( ym==0)
        {
            toastr.error('请选择年，月');
            return;
        }

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (data) {
                console.dir(data);
                console.info(data.url_img);
                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show( pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (getStringFromSQL(`select id from  dzpz where corpid='${corpid}'  and ym= ${ym} and pzh='${pzh}' `) != '') {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6566e3fe9932bfa1d16e4234
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:40:53.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if( ym==0)
        {
            toastr.error('请选择年，月');
            return;
        }

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (data) {
                console.dir(data);
                console.info(data.url_img);
                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show( pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectName);
                
                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (getStringFromSQL(`select id from  dzpz where corpid='${corpid}'  and ym= ${ym} and pzh='${pzh}' `) != '') {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6566e3fe9932bfa1d16e423a
scriptid: 655a1eb99932174d03378091
tablename: app_script
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:43:33.000
script:
function create_pz(corpid, ym, pzh, archive_id) {
    var ds = newDataStore("", "select  * from  dzpz_pz");
    ds.setUpdateProperty("dzpz_pz", "id", "*", "id");
    ds.insertRow(0);
    var newid = newGuid();
    ds.setValue(0, {
        id: newid,
        gguid: newid,
        billno: newid,
        billdate: newDate(),
        userid: currentUserId(),
        username: currentUserShowName(),
        corpid: corpid,
        ym: ym,
        pzh: pzh
    }
    );

    ds.executeAfterUpdate(` update  app_archive set gguid='${newid}'  where id='${archive_id}' `);
    if(  ds.update(true)) return '';
    return ds.getErrorMessage();

} 


function pzh_exists(corpid, ym, pzh)
{
     return getStringFromSQL(`select id from  dzpz where corpid='${corpid}'  and ym= ${ym} and pzh='${pzh}' `) != '';
}


id: 6566e3fe9932bfa1d16e423e
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:44:32.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if( ym==0)
        {
            toastr.error('请选择年，月');
            return;
        }

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (data) {
                console.dir(data);
                console.info(data.url_img);
                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show( pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectName);
                
                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if  (  pzh_exists(corpid, ym, pzh))  {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6566e3fe9932bfa1d16e4242
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:44:46.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if( ym==0)
        {
            toastr.error('请选择年，月');
            return;
        }

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (data) {
                console.dir(data);
                console.info(data.url_img);
                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show( pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectName);
                
                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if  (  pzh_exists(corpid, ym, pzh))  {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6566ecb29932bfa1d16e425c
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 125.119.83.85
username: sa
createdate: 2023.11.29 15:50:49.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if( ym==0)
        {
            toastr.error('请选择年，月');
            return;
        }

        uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },


            function (data) {
                console.dir(data);
                console.info(data.url_img);
                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show( pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectname);
                
                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },

            function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if  (  pzh_exists(corpid, ym, pzh))  {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                config.objectName = name;

                return true;
            }
        );
    });
}


id: 6567077099320041501aff81
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 09:37:08.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if( ym==0)
        {
            toastr.error('请选择年，月');
            return;
        }

        do_upload();

        
    });
}


function  do_upload()
{
    uploadFolder({
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },
        {
            threadCount:4,

            //一个文件上传成功后，创建相应的凭证记录
            onFileUploaded:function (data , file) {
                console.dir(data);
                 
                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show( pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectname);
                
                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },

            //文件上传前做校验
            onFilter:function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if  (  pzh_exists(corpid, ym, pzh))  {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                config.objectName = name;

                return true;
            },

            onAllFilesUploaded:function()
            {
                $.alter("全部上传完成");
                toastr.hide();
            }
        );
}


id: 6567077099320041501aff85
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 09:39:25.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if (ym == 0) {
            toastr.error('请选择年，月');
            return;
        }

        do_upload();


    });
}


function do_upload() {
    uploadFolder({
        fileType: "pdf",
        serverIndex: 1,
        logTable: 'app_archive',
        tableName: 'dzpz_pz',
        gguid: '', //
        path: "凭证归档/" + corpid + "/" + ym

    },
        {
            threadCount: 4,

            //一个文件上传成功后，创建相应的凭证记录
            onFileUploaded: function (data, file) {
                console.dir(data);

                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show(pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectname);

                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },
            //上传进度显示 
            onUploadProgress:function(percent, file)
            {
                toastr.show( file.name+ "  "+ percent+'%' );
            },

            //文件上传前做校验
            onFilter: function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (pzh_exists(corpid, ym, pzh)) {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                config.objectName = name;

                return true;
            },

            onAllFilesUploaded: function () {
                $.alter("全部上传完成");
                toastr.hide();
            }
        }
    );
}


id: 6567f15199320041501aff89
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 10:20:01.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if (ym == 0) {
            toastr.error('请选择年，月');
            return;
        }

        do_upload();


    });
}


function do_upload() {
    uploadFolder(
        {
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },
        {
            threadCount: 4,

            //一个文件上传成功后，创建相应的凭证记录
            onFileUploaded: function (data, file) {
                console.dir(data);

                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show(pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectname);

                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },
            //上传进度显示 
            onUploadProgress: function (percent, file) {
                toastr.show(file.name + "  " + percent + '%');
            },

            //文件上传前做校验
            onFilter: function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (pzh_exists(corpid, ym, pzh)) {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                config.objectName = name;

                return true;
            },

            onAllFilesUploaded: function () {
                $.alter("全部上传完成");
                toastr.hide();
            }
        }
    );
}


id: 6567f15199320041501aff8d
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 10:21:35.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if (ym == 0) {
            toastr.error('请选择年，月');
            return;
        }

        do_upload();


    });
}


function do_upload() {
    uploadFolder(
        {
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        }
    );
}


id: 6567f15199320041501aff95
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 10:23:39.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if (ym == 0) {
            toastr.error('请选择年，月');
            return;
        }

         uploadFolder({
        path: "/a/b/c"

    },

        
        {
            onFileUploaded: function (ret, file) {
                console.dir(ret);
                console.info(ret.url_img);
            },

            onFilter: function (oneConfig, file) {
                console.dir(file);
                let name = file.name;
                if (name.endsWith('.pdf')) {
                    oneConfig.objectName = "aaaa.pdf";
                    return true;
                }
                toastr.error(name + "不是pdf， 禁止上传");

                return false;
            },

            onAllFilesUploaded: function () {
                console.info("all over");
            }
        }
    );


    });
}


function do_upload() {
    uploadFolder(
        {
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },
        {
            threadCount: 4,

            //一个文件上传成功后，创建相应的凭证记录
            onFileUploaded: function (data, file) {
                console.dir(data);

                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show(pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectname);

                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },
            //上传进度显示 
            onUploadProgress: function (percent, file) {
                toastr.show(file.name + "  " + percent + '%');
            },

            //文件上传前做校验
            onFilter: function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (pzh_exists(corpid, ym, pzh)) {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                config.objectName = name;

                return true;
            },

            onAllFilesUploaded: function () {
                $.alter("全部上传完成");
                toastr.hide();
            }
        }
    );
}


id: 6567f15199320041501aff9e
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 10:25:15.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if (ym == 0) {
            toastr.error('请选择年，月');
            return;
        }

        do_upload();

    });
}


function do_upload( corpid , ym ) {
    uploadFolder( {
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },
        {
            threadCount: 4,

            //一个文件上传成功后，创建相应的凭证记录
            onFileUploaded: function (data, file) {
                console.dir(data);

                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show(pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectname);

                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },
            //上传进度显示 
            onUploadProgress: function (percent, file) {
                toastr.show(file.name + "  " + percent + '%');
            },

            //文件上传前做校验
            onFilter: function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (pzh_exists(corpid, ym, pzh)) {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                config.objectName = name;

                return true;
            },

            onAllFilesUploaded: function () {
                $.alter("全部上传完成");
                toastr.hide();
            }
        }
    );
}


id: 6567f15199320041501affa2
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 10:26:19.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if (ym == 0) {
            toastr.error('请选择年，月');
            return;
        }

        do_upload( corpid ,ym);

    });
}


function do_upload( corpid , ym ) {
    uploadFolder( {
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },
        {
            threadCount: 4,

            //一个文件上传成功后，创建相应的凭证记录
            onFileUploaded: function (data, file) {
                console.dir(data);

                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show(pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectname);

                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },
            //上传进度显示 
            onUploadProgress: function (percent, file) {
                toastr.show(file.name + "  " + percent + '%');
            },

            //文件上传前做校验
            onFilter: function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (pzh_exists(corpid, ym, pzh)) {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                config.objectName = name;

                return true;
            },

            onAllFilesUploaded: function () {
                $.alter("全部上传完成");
                toastr.hide();
            }
        }
    );
}


id: 6567f15199320041501affa6
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 10:26:37.000
script:
"use strict";

function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if (ym == 0) {
            toastr.error('请选择年，月');
            return;
        }

        do_upload( corpid ,ym);

    });
}


function do_upload( corpid , ym ) {
    uploadFolder( {
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },
        {
            threadCount: 4,

            //一个文件上传成功后，创建相应的凭证记录
            onFileUploaded: function (data, file) {
                console.dir(data);

                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show(pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectname);

                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },
            //上传进度显示 
            onUploadProgress: function (percent, file) {
                toastr.show(file.name + "  " + percent + '%');
            },

            //文件上传前做校验
            onFilter: function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (pzh_exists(corpid, ym, pzh)) {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                config.objectName = name;

                return true;
            },

            onAllFilesUploaded: function () {
                $.alter("全部上传完成");
                toastr.hide();
            }
        }
    );
}


id: 6567f15199320041501affaa
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 10:26:44.000
script:
"use strict";

function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if (ym == 0) {
            toastr.error('请选择年，月');
            return;
        }

        do_upload( corpid ,ym);

    });
}


function do_upload( corpid  ) {
    uploadFolder( {
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },
        {
            threadCount: 4,

            //一个文件上传成功后，创建相应的凭证记录
            onFileUploaded: function (data, file) {
                console.dir(data);

                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show(pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectname);

                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },
            //上传进度显示 
            onUploadProgress: function (percent, file) {
                toastr.show(file.name + "  " + percent + '%');
            },

            //文件上传前做校验
            onFilter: function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (pzh_exists(corpid, ym, pzh)) {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                config.objectName = name;

                return true;
            },

            onAllFilesUploaded: function () {
                $.alter("全部上传完成");
                toastr.hide();
            }
        }
    );
}


id: 6567f15199320041501affae
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 10:27:23.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if (ym == 0) {
            toastr.error('请选择年，月');
            return;
        }

        do_upload( corpid ,ym);

    });
}


function do_upload( corpid  ,ym) {
    uploadFolder( {
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },
        {
            threadCount: 4,

            //一个文件上传成功后，创建相应的凭证记录
            onFileUploaded: function (data, file) {
                console.dir(data);

                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show(pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectname);

                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },
            //上传进度显示 
            onUploadProgress: function (percent, file) {
                toastr.show(file.name + "  " + percent + '%');
            },

            //文件上传前做校验
            onFilter: function (file, config) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (pzh_exists(corpid, ym, pzh)) {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                config.objectName = name;

                return true;
            },

            onAllFilesUploaded: function () {
                $.alter("全部上传完成");
                toastr.hide();
            }
        }
    );
}


id: 6567f15199320041501affb2
scriptid: 655a1eb99932174d03378096
tablename: app_template
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 10:29:32.000
script:
function cb_upload_onClick() {


    form.save(false, function () {
        let corpid = $uploadpz_ds.getString(0, "corpid");
        let ym = $uploadpz_ds.getString(0, "ym");
        if (ym == 0) {
            toastr.error('请选择年，月');
            return;
        }

        do_upload( corpid ,ym);

    });
}


function do_upload( corpid  ,ym) {
    uploadFolder( {
            fileType: "pdf",
            serverIndex: 1,
            logTable: 'app_archive',
            tableName: 'dzpz_pz',
            gguid: '', //
            path: "凭证归档/" + corpid + "/" + ym

        },
        {
            threadCount: 4,

            //一个文件上传成功后，创建相应的凭证记录
            onFileUploaded: function (data, file) {
                console.dir(data);

                let row = $uploadpzmx_ds.insertRow(99999);
                let pzh = data.filename;
                pzh = pzh.substring(pzh.lastIndexOf("/") + 1, pzh.lastIndexOf("."));
                toastr.show(pzh);
                $uploadpzmx_ds.setValue(row, "pzh", pzh);
                $uploadpzmx_ds.setValue(row, "url", data.objectname);

                let state = 0;
                create_pz(corpid, ym, pzh, data.id, function (info) {  //创建凭证记录
                    if (info == '') {
                        state = 1;
                        info = "成功上传";
                    } else {
                        state = 0;
                    }
                    $uploadpzmx_ds.setValue(row, "state", state);
                    $uploadpzmx_ds.setValue(row, "info", info);
                    toastr.hide();
                    form.save(false);
                });

            },
            //上传进度显示 
            onUploadProgress: function (percent, file) {
                toastr.show(file.name + "  " + percent + '%');
            },

            //文件上传前做校验
            onFilter: function (  oneConfig , file ) {
                console.dir(file);
                let name = file.name.toLowerCase();
                if (!name.endsWith('.pdf')) {
                    console.info(name + "不是pdf，无需上传");
                    return false;
                }


                let pzh = name.substring(0, name.lastIndexOf('.'));

                if (pzh_exists(corpid, ym, pzh)) {
                    let row = $uploadpzmx_ds.insertRow(99999);
                    $uploadpzmx_ds.setValue(row, "pzh", pzh);
                    $uploadpzmx_ds.setValue(row, "state", 0);
                    $uploadpzmx_ds.setValue(row, "info", pzh + "已存在，禁止上传。如需覆盖，请先删除该凭证，再上传");
                    return false;
                }
                //指定上传后的文件名
                oneConfig.objectName = name;

                return true;
            },

            onAllFilesUploaded: function () {
                $.alter("全部上传完成");
                toastr.hide();
            }
        }
    );
}


id: 6567f15199320041501affc5
scriptid: 60a31c3c5db27838e0c0129e
tablename: app_script
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 13:17:25.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 ) ;

    return {
        success: true,
        message: "",
        session: session,
        sql: {"default": [`delete app_archive where gguid='${gguid}'`]}  // 归档信息删除
    };

}


id: 6567f15199320041501affd4
scriptid: 60a31c3c5db27838e0c0129e
tablename: app_script
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 13:21:52.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 app_archive where gguid='${gguid}'` ;
    println( sql);
    
    return {
        success: true,
        message: "",
        session: session,
        sql: {"default": [sql]}  // 归档信息删除
    };

}


id: 6567f15199320041501affda
scriptid: 60a31c3c5db27838e0c0129e
tablename: app_script
clientip: 122.233.66.137
username: sa
createdate: 2023.11.30 13:23:13.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]}  // 归档信息删除
    };

}


id: 663879c89932a08a57e3ead3
scriptid: 66382c259932a08a57e3e707
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.07 22:20:38.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 ) {
    runSQL("",` update pzb set pzs= (select count(*) from pzbmx where pzbmx.gguid=${gguid} ) where  gguid=${gguid}` ,true);

}


id: 663a3c5f9932a08a57e3ecc6
scriptid: 663a3aa59932a08a57e3eba1
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.07 23:14:24.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);
    var corpid= param.corpid ||'';
    var ym = param.ym || ''; 

    //生成主记录

  var sql= ` select id , id as gguid , id as billno , 1 as userid , '管理员' as username , 0 as deleteflag ,
            corpid , ym  
            from (
                select distinct  concat( corpid , '-', ym ) as id , corpid , ym   from dzpz_pz   
            union 
                select distinct  concat ( corpid , '-' ,  y*100+ m ) as id , corpid ,   y*100+ m   as ym   from pzdjex 
            ) a  
            where id is not null and corpid is not null  and ym is not null 
            order by id 
        ` ; 
        

 



}


id: 663a3c5f9932a08a57e3eccc
scriptid: 663a3aa59932a08a57e3eba1
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.07 23:25:46.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);
    var corpid= param.corpid ||'';
    var ym = param.ym || ''; 

    var  minYM =  formatDate(  nextDate( newDate()  , -12 * 5 ,'month') , 'yyyyMM');
    
    var where=" and ym>= ${minYM} ";
    if( ym!='' )  where =  where  + ` and (corpid='${corpid}' and ym= ${ym} ) ` ;

     
    //生成主记录

    var sql= ` select id , id as gguid , id as billno , 1 as userid , '管理员' as username , 0 as deleteflag ,
            corpid , ym  
            from (
                select distinct  concat( corpid , '-', ym ) as id , corpid , ym   from dzpz_pz   
            union 
                select distinct  concat ( corpid , '-' ,  y*100+ m ) as id , corpid ,   y*100+ m   as ym   from pzdjex 
            ) a  
            where id is not null and corpid is not null  and ym is not null  ${where} 
            order by id 
        ` ; 

    dbTransfer('', sql, 'pzb', 'id',true, 1000, '','', '', 0, 0, -5) ;

    //凭证记录

    sql= `
    select  * 
    from (
        select distinct  concat( corpid , '-', ym ,'-',pzh ) as id ,  concat( corpid , '-', ym   ) as gguid  , corpid , ym  , pzh  from dzpz_pz   
        union 
        select distinct  concat( corpid , '-' ,  y*100+ m ,'-',pzh ) as id ,  concat ( corpid , '-' ,  y*100+ m ) as gguid , corpid ,   y*100+ m   as ym  ,pzh  from pzdjex 
            where y is not null and m is not null and  corpid is not null 
        ) a  where id is not null and corpid is not null  and ym is not null ${where} 
    order by id 
    
    `

    dbTransfer('', sql, 'pzbmx', 'id',true, 1000, '','', '', 0, 0, -5) ;


    return 'over' ;


}


id: 663a3c5f9932a08a57e3ecd8
scriptid: 663a3aa59932a08a57e3eba1
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.07 23:34:18.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);
    var corpid= param.corpid ||'';
    var ym = param.ym || ''; 

    var  minYM =  formatDate(  nextDate( newDate()  , -12 * 5 ,'month') , 'yyyyMM');
    
    var where=` and ym>= ${minYM} `;
    if( ym!='' )  where =  where  + ` and (corpid='${corpid}' and ym= ${ym} ) ` ;

     
    //生成主记录

    var sql= ` select id , id as gguid , id as billno , 1 as userid , '管理员' as username , 0 as deleteflag ,
            corpid , ym  
            from (
                select distinct  concat( corpid , '-', ym ) as id , corpid , ym   from dzpz_pz   
            union 
                select distinct  concat ( corpid , '-' ,  y*100+ m ) as id , corpid ,   y*100+ m   as ym   from pzdjex 
            ) a  
            where id is not null and corpid is not null  and ym is not null  ${where} 
            order by id 
        ` ; 

    dbTransfer('', sql, 'pzb', 'id',true, 1000, '','', '', 0, 0, -5) ;

    //凭证记录

    sql= `
    select  * 
    from (
        select distinct  concat( corpid , '-', ym ,'-',pzh ) as id ,  concat( corpid , '-', ym   ) as gguid  , corpid , ym  , pzh  from dzpz_pz   
        union 
        select distinct  concat( corpid , '-' ,  y*100+ m ,'-',pzh ) as id ,  concat ( corpid , '-' ,  y*100+ m ) as gguid , corpid ,   y*100+ m   as ym  ,pzh  from pzdjex 
            where y is not null and m is not null and  corpid is not null 
        ) a  where id is not null and corpid is not null  and ym is not null ${where} 
    order by id 
    
    `

    dbTransfer('', sql, 'pzbmx', 'id',true, 1000, '','', '', 0, 0, -5) ;


    return 'over' ;


}


id: 663a3c5f9932a08a57e3ece4
scriptid: 663a3aa59932a08a57e3eba1
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.07 23:36:18.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);
    var corpid= param.corpid ||'';
    var ym = param.ym || ''; 

    var  minYM =  formatDate(  nextDate( newDate()  , -12 * 5 ,'month') , 'yyyyMM');
    
    var where=` and ym>= ${minYM} `;
    if( ym!='' )  where =  where  + ` and (corpid='${corpid}' and ym= ${ym} ) ` ;

     
    //生成主记录

    var sql= ` select id , id as gguid , id as billno , 1 as userid , '管理员' as username , 0 as deleteflag ,
            corpid , ym  
            from (
                select distinct  concat( corpid , '-', ym ) as id , corpid , ym   from dzpz_pz   
            union 
                select distinct  concat ( corpid , '-' ,  y*100+ m ) as id , corpid ,   y*100+ m   as ym   from pzdjex 
            ) a  
            where id is not null and corpid is not null  and ym is not null  ${where} 
            order by id 
        ` ; 

    dbTransfer('', sql, 'pzb', 'id',true, 1000, '','', '', 0, 0, -5) ;

    //凭证记录

    sql= `
    select  * 
    from (
        select distinct  concat( corpid , '-', ym ,'-',pzh ) as id ,  concat( corpid , '-', ym   ) as gguid  , corpid , ym  , pzh  from dzpz_pz   
        union 
        select distinct  concat( corpid , '-' ,  y*100+ m ,'-',pzh ) as id ,  concat ( corpid , '-' ,  y*100+ m ) as gguid , corpid ,   y*100+ m   as ym  ,pzh  from pzdjex 
            where y is not null and m is not null and  corpid is not null 
        ) a  where id is not null and corpid is not null  and ym is not null ${where} 
    order by id 
    
    `

    dbTransfer('', sql, 'pzbmx', 'id',true, 1000, '','', '', 0, 0, -5) ;

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

    return 'over' ;


}


id: 663a4ab29932a08a57e3ecea
scriptid: 663a3aa59932a08a57e3eba1
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.07 23:37:23.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);
    var corpid= param.corpid ||'';
    var ym = param.ym || ''; 

    var  minYM =  formatDate(  nextDate( newDate()  , -12 * 10 ,'month') , 'yyyyMM');
    
    var where=` and ym>= ${minYM} `;
    if( ym!='' )  where =  where  + ` and (corpid='${corpid}' and ym= ${ym} ) ` ;

     
    //生成主记录

    var sql= ` select id , id as gguid , id as billno , 1 as userid , '管理员' as username , 0 as deleteflag ,
            corpid , ym  
            from (
                select distinct  concat( corpid , '-', ym ) as id , corpid , ym   from dzpz_pz   
            union 
                select distinct  concat ( corpid , '-' ,  y*100+ m ) as id , corpid ,   y*100+ m   as ym   from pzdjex 
            ) a  
            where id is not null and corpid is not null  and ym is not null  ${where} 
            order by id 
        ` ; 

    dbTransfer('', sql, 'pzb', 'id',true, 1000, '','', '', 0, 0, -5) ;

    //凭证记录

    sql= `
    select  * 
    from (
        select distinct  concat( corpid , '-', ym ,'-',pzh ) as id ,  concat( corpid , '-', ym   ) as gguid  , corpid , ym  , pzh  from dzpz_pz   
        union 
        select distinct  concat( corpid , '-' ,  y*100+ m ,'-',pzh ) as id ,  concat ( corpid , '-' ,  y*100+ m ) as gguid , corpid ,   y*100+ m   as ym  ,pzh  from pzdjex 
            where y is not null and m is not null and  corpid is not null 
        ) a  where id is not null and corpid is not null  and ym is not null ${where} 
    order by id 
    
    `

    dbTransfer('', sql, 'pzbmx', 'id',true, 1000, '','', '', 0, 0, -5) ;

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

    return 'over' ;


}


id: 663a4ab29932a08a57e3ecf0
scriptid: 663a3aa59932a08a57e3eba1
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.07 23:38:20.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);
    var corpid= param.corpid ||'';
    var ym = param.ym || ''; 

    var  minYM =  formatDate(  nextDate( newDate()  , -12 * 10 ,'month') , 'yyyyMM');
    
    var where=` and ym>= ${minYM} `;
    if( ym!='' )  where =  where  + ` and (corpid='${corpid}' and ym= ${ym} ) ` ;

     
    //生成主记录

    var sql= ` select id , id as gguid , id as billno , 1 as userid , '管理员' as username , 0 as deleteflag ,
            corpid , ym  
            from (
                select distinct  concat( corpid , '-', ym ) as id , corpid , ym   from dzpz_pz   
            union 
                select distinct  concat ( corpid , '-' ,  y*100+ m ) as id , corpid ,   y*100+ m   as ym   from pzdjex 
            ) a  
            where id is not null and corpid is not null  and ym is not null  ${where} 
            order by id 
        ` ; 

    dbTransfer('', sql, 'pzb', 'id',true, 1000, '','', '', 0, 0, -5) ;

    //凭证记录

    sql= `
    select  * 
    from (
        select distinct  concat( corpid , '-', ym ,'-',pzh ) as id ,  concat( corpid , '-', ym   ) as gguid  , corpid , ym  , pzh  from dzpz_pz   
        union 
        select distinct  concat( corpid , '-' ,  y*100+ m ,'-',pzh ) as id ,  concat ( corpid , '-' ,  y*100+ m ) as gguid , corpid ,   y*100+ m   as ym  ,pzh  from pzdjex 
            where y is not null and m is not null and  corpid is not null 
        ) a  where id is not null and corpid is not null  and ym is not null ${where} 
    order by id 
    
    `

    dbTransfer('', sql, 'pzbmx', 'id',true, 1000, '','', '', 0, 0, -5) ;

    runSQL("" , `create index  di_pzbmx_corpid_ym on  pzbmx ( corpid, ym) ` ,true);

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

    return 'over' ;


}


id: 663a4bf49932a08a57e3ed99
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.07 23:49:40.000
script:
function cb_auto_pzh_onClick()
{
    showInfoPane( "* 正在自动构造凭证清册") ;
    setTimeout( function()
    {
        runTask( "", {corpid: $pzbmx_ds.getString(0,"corpid") , ym: $pzb_ds.getString(0,"ym")} , function()
        {
            hideInfoPane(   ) ;
            toastr.info("构建完成");
            smartRetrieve( book.sheet0 , 'pzbmx');
        });
    },500);
}


id: 663a4bf49932a08a57e3ed9d
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.07 23:50:33.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("构建完成");
            smartRetrieve( book.sheet0 , 'pzbmx');
        });
    },500);
}


id: 663a4bf49932a08a57e3eda8
scriptid: 66382c259932a08a57e3e707
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.07 23:52:04.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 ) {
    runSQL("",` update pzb set pzs= (select count(*) from pzbmx where pzbmx.gguid='${gguid}' ) where  gguid= '${gguid}' ` ,true);

}


id: 663a4bf49932a08a57e3edac
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:01:15.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("构建完成");
            smartRetrieve(book.sheet0, 'pzbmx');
        });
    }, 500);
}


function cb_add_pzh_onClick() {

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

                action: function () {

                    return true;
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

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

        });

}


id: 663a50789932a08a57e3edb0
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:02:00.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("构建完成");
            smartRetrieve(book.sheet0, 'pzbmx');
        });
    }, 500);
}


function cb_add_pzh_onClick() {

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

                action: function () {

                    return true;
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

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

        });

}


id: 663a50789932a08a57e3edb4
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:02:43.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("构建完成");
            smartRetrieve(book.sheet0, 'pzbmx');
        });
    }, 500);
}


function cb_add_pzh_onClick() {

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

                action: function () {

                    return true;
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

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

        });

}


id: 663a50789932a08a57e3edb8
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:04:26.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("构建完成");
            smartRetrieve(book.sheet0, 'pzbmx');
        });
    }, 500);
}


function cb_add_pzh_onClick() {

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

                action: function () {

                    return true;
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

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

        });

}


id: 663a50789932a08a57e3edbc
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:15:44.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("构建完成");
            smartRetrieve(book.sheet0, 'pzbmx');
        });
    }, 500);
}


function cb_add_pzh_onClick() {

    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; 
                    }
                    
                    back_add_pzh( $pzbmx_ds.getString(0, "gguid"),
                                   $pzbmx_ds.getString(0, "corpid"), 
                                  $pzb_ds.getString(0, "ym") , 
                                  range.pzh  ,function (ret) {
                                        hideInfoPane();
                                        toastr.info( ret.message);
                                        
                                   });
                    return true; 
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

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

        });

}


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 pzh=[];
    
    let 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};
    
}


id: 663a50789932a08a57e3edc0
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:16:17.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("构建完成");
            smartRetrieve(book.sheet0, 'pzbmx');
        });
    }, 500);
}


function cb_add_pzh_onClick() {

    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( '*正在添加凭证号') ;
                    
                    back_add_pzh( $pzbmx_ds.getString(0, "gguid"),
                                   $pzbmx_ds.getString(0, "corpid"), 
                                  $pzb_ds.getString(0, "ym") , 
                                  range.pzh  ,function (ret) {
                                        hideInfoPane();
                                        toastr.info( ret.message);
                                        
                                   });
                    return true; 
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

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

        });

}


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 pzh=[];
    
    let 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};
    
}


id: 663a50789932a08a57e3edc6
scriptid: 663a3aa59932a08a57e3eba1
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:19:36.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);
    var corpid= param.corpid ||'';
    var ym = param.ym || ''; 

    var  minYM =  formatDate(  nextDate( newDate()  , -12 * 10 ,'month') , 'yyyyMM');
    
    var where=` and ym>= ${minYM} `;
    if( ym!='' )  where =  where  + ` and (corpid='${corpid}' and ym= ${ym} ) ` ;

     
    //生成主记录

    var sql= ` select id , id as gguid , id as billno , 1 as userid , '管理员' as username , 0 as deleteflag ,
            corpid , ym  
            from (
                select distinct  concat( corpid , '-', ym ) as id , corpid , ym   from dzpz_pz   
            union 
                select distinct  concat ( corpid , '-' ,  y*100+ m ) as id , corpid ,   y*100+ m   as ym   from pzdjex 
            ) a  
            where id is not null and corpid is not null  and ym is not null  ${where} 
            order by id 
        ` ; 

    dbTransfer('', sql, 'pzb', 'id',true, 1000, '','', '', 0, 0, -5) ;

    //凭证记录

    sql= `
    select  * 
    from (
        select distinct  concat( corpid , '-', ym ,'-',pzh ) as id ,  concat( corpid , '-', ym   ) as gguid  , corpid , ym  , pzh  from dzpz_pz   
        union 
        select distinct  concat( corpid , '-' ,  y*100+ m ,'-',pzh ) as id ,  concat ( corpid , '-' ,  y*100+ m ) as gguid , corpid ,   y*100+ m   as ym  ,pzh  from pzdjex 
            where y is not null and m is not null and  corpid is not null 
        ) a  where id is not null and corpid is not null  and ym is not null ${where} 
    order by id 
    
    `

    dbTransfer('', sql, 'pzbmx', 'id',true, 1000, '','', '', 0, 0, -5) ;

    runSQL("" , `create index  di_pzbmx_corpid_ym on  pzbmx ( corpid, ym) ` ,true);
    
    runSQL("" , `create unique index  ui_pzbmx_pzh on  pzbmx ( corpid, ym ,pzh) ` ,true);
    

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

    return 'over' ;


}


id: 663a50789932a08a57e3edcc
scriptid: 66382c259932a08a57e3e707
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:24:03.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 ) {
    runSQL("",` update pzb set pzs= (select count(*) from pzbmx where pzbmx.gguid='${gguid}' ) where  gguid= '${gguid}' ` ,true);

}



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);
            if ( ds.update(true)) c++ ; //如果存在，更新会失败，也没关系
            
    }

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

}


id: 663a50789932a08a57e3edd0
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:25:22.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.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( '*正在添加凭证号') ;
                    
                    back_add_pzh( $pzbmx_ds.getString(0, "gguid"),
                                   $pzbmx_ds.getString(0, "corpid"), 
                                  $pzb_ds.getString(0, "ym") , 
                                  range.pzh  ,function (ret) {
                                        hideInfoPane();
                                        toastr.info( ret.message);
                                          reloadData();
                                        
                                   });
                    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 pzh=[];
    
    let 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};
    
}


id: 663a50789932a08a57e3edd8
scriptid: 66382c259932a08a57e3e707
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:26:23.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_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);
            if ( ds.update(true)) c++ ; //如果存在，更新会失败，也没关系
            
    }

    update_pzs( gguid);

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

}


id: 663a50789932a08a57e3edde
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:30:56.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.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( $pzbmx_ds.getString(0, "gguid"),
                                   $pzbmx_ds.getString(0, "corpid"), 
                                  $pzb_ds.getString(0, "ym") , 
                                  range.pzh  ,function (ret) {
                                        hideInfoPane();
                                        toastr.info( ret.message);
                                          reloadData();
                                        
                                   });
                    },400);
                    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 pzh=[];
    
    let 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};
    
}


id: 663a50789932a08a57e3ede2
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:30:59.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.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($pzbmx_ds.getString(0, "gguid"),
                            $pzbmx_ds.getString(0, "corpid"),
                            $pzb_ds.getString(0, "ym"),
                            range.pzh, function (ret) {
                                hideInfoPane();
                                toastr.info(ret.message);
                                reloadData();

                            });
                    }, 400);
                    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 pzh = [];

    let 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 };

}


id: 663a50789932a08a57e3ede6
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:31:46.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.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($pzbmx_ds.getString(0, "gguid"),
                            $pzbmx_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 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 pzh = [];

    let 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 };

}


id: 663a50789932a08a57e3edea
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:36:50.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.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($pzbmx_ds.getString(0, "gguid"),
                            $pzbmx_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.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_delete_pzh($pzbmx_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 pzh = [];

    let 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 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: 663a50789932a08a57e3edf0
scriptid: 66382c259932a08a57e3e707
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:40:04.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_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);
            if ( ds.update(true)) c++ ; //如果存在，更新会失败，也没关系
            
    }

    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: 663a50789932a08a57e3edf4
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 00:41:07.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.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($pzbmx_ds.getString(0, "gguid"),
                            $pzbmx_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.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($pzbmx_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 pzh = [];

    let 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 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: 663a67429932a08a57e3ee1f
scriptid: 66382c259932a08a57e3e707
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 07:02:31.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_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++ ; //如果存在，更新会失败，也没关系
            
    }

    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: 663a67429932a08a57e3ee25
scriptid: 663a3aa59932a08a57e3eba1
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 07:04:16.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);
    var corpid= param.corpid ||'';
    var ym = param.ym || ''; 

    var  minYM =  formatDate(  nextDate( newDate()  , -12 * 10 ,'month') , 'yyyyMM');
    
    var where=` and ym>= ${minYM} `;
    if( ym!='' )  where =  where  + ` and (corpid='${corpid}' and ym= ${ym} ) ` ;

     
    //生成主记录

    var sql= ` select id , id as gguid , id as billno , 1 as userid , '管理员' as username , 0 as deleteflag ,
            corpid , ym  
            from (
                select distinct  concat( corpid , '-', ym ) as id , corpid , ym   from dzpz_pz   
            union 
                select distinct  concat ( corpid , '-' ,  y*100+ m ) as id , corpid ,   y*100+ m   as ym   from pzdjex 
            ) a  
            where id is not null and corpid is not null  and ym is not null  ${where} 
            order by id 
        ` ; 

    dbTransfer('', sql, 'pzb', 'id',true, 1000, '','', '', 0, 0, -5) ;

    runSQL("","update pzb set billdate ='"+ date2yyyymmdd( newDate())+"' where  billdate is null ",true);

    //凭证记录

    sql= `
    select  * 
    from (
        select distinct  concat( corpid , '-', ym ,'-',pzh ) as id ,  concat( corpid , '-', ym   ) as gguid  , corpid , ym  , pzh  from dzpz_pz   
        union 
        select distinct  concat( corpid , '-' ,  y*100+ m ,'-',pzh ) as id ,  concat ( corpid , '-' ,  y*100+ m ) as gguid , corpid ,   y*100+ m   as ym  ,pzh  from pzdjex 
            where y is not null and m is not null and  corpid is not null 
        ) a  where id is not null and corpid is not null  and ym is not null ${where} 
    order by id 
    
    `

    dbTransfer('', sql, 'pzbmx', 'id',true, 1000, '','', '', 0, 0, -5) ;

    runSQL("","update pzbmx set createdate ='"+ date2yyyymmdd( newDate())+"' where  createdate is null ",true);

    runSQL("" , `create index  di_pzbmx_corpid_ym on  pzbmx ( corpid, ym) ` ,true);
    
    runSQL("" , `create unique index  ui_pzbmx_pzh on  pzbmx ( corpid, ym ,pzh) ` ,true);
    

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

    return 'over' ;


}


id: 663a67429932a08a57e3ee2b
scriptid: 663a3aa59932a08a57e3eba1
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 07:04:56.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);
    var corpid= param.corpid ||'';
    var ym = param.ym || ''; 

    var  minYM =  formatDate(  nextDate( newDate()  , -12 * 10 ,'month') , 'yyyyMM');
    
    var where=` and ym>= ${minYM} `;
    if( ym!='' )  where =  where  + ` and (corpid='${corpid}' and ym= ${ym} ) ` ;

     
    //生成主记录

    var sql= ` select id , id as gguid , id as billno , 1 as userid , '管理员' as username , 0 as deleteflag ,
            corpid , ym  
            from (
                select distinct  concat( corpid , '-', ym ) as id , corpid , ym   from dzpz_pz   
            union 
                select distinct  concat ( corpid , '-' ,  y*100+ m ) as id , corpid ,   y*100+ m   as ym   from pzdjex 
            ) a  
            where id is not null and corpid is not null  and ym is not null  ${where} 
            order by id 
        ` ; 

    dbTransfer('', sql, 'pzb', 'id',true, 1000, '','', '', 0, 0, -5) ;

    runSQL("","update pzb set billdate ='"+ date2yyyymmdd( newDate())+"' where  billdate is null ",true);

    //凭证记录

    sql= `
    select  * 
    from (
        select distinct  concat( corpid , '-', ym ,'-',pzh ) as id ,  concat( corpid , '-', ym   ) as gguid  , corpid , ym  , pzh  from dzpz_pz   
        union 
        select distinct  concat( corpid , '-' ,  y*100+ m ,'-',pzh ) as id ,  concat ( corpid , '-' ,  y*100+ m ) as gguid , corpid ,   y*100+ m   as ym  ,pzh  from pzdjex 
            where y is not null and m is not null and  corpid is not null 
        ) a  where id is not null and corpid is not null  and ym is not null ${where} 
    order by id 
    
    `

    dbTransfer('', sql, 'pzbmx', 'id',true, 1000, '','', '', 0, 0, -5) ;

    runSQL("",`update pzbmx set createdate ='"+ date2yyyymmdd( newDate())+"' where  createdate is null   ${where}`,true);

    runSQL("" , `create index  di_pzbmx_corpid_ym on  pzbmx ( corpid, ym) ` ,true);
    
    runSQL("" , `create unique index  ui_pzbmx_pzh on  pzbmx ( corpid, ym ,pzh) ` ,true);
    

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

    return 'over' ;


}


id: 663a67429932a08a57e3ee31
scriptid: 663a3aa59932a08a57e3eba1
tablename: app_script
clientip: 122.234.141.92
username: sa
createdate: 2024.05.08 07:06:11.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);
    var corpid= param.corpid ||'';
    var ym = param.ym || ''; 

    var  minYM =  formatDate(  nextDate( newDate()  , -12 * 10 ,'month') , 'yyyyMM');
    
    var where=` and ym>= ${minYM} `;
    if( ym!='' )  where =  where  + ` and (corpid='${corpid}' and ym= ${ym} ) ` ;

     
    //生成主记录

    var sql= ` select id , id as gguid , id as billno , 1 as userid , '管理员' as username , 0 as deleteflag ,
            corpid , ym  
            from (
                select distinct  concat( corpid , '-', ym ) as id , corpid , ym   from dzpz_pz   
            union 
                select distinct  concat ( corpid , '-' ,  y*100+ m ) as id , corpid ,   y*100+ m   as ym   from pzdjex 
            ) a  
            where id is not null and corpid is not null  and ym is not null  ${where} 
            order by id 
        ` ; 

    dbTransfer('', sql, 'pzb', 'id',true, 1000, '','', '', 0, 0, -5) ;

    runSQL("","update pzb set billdate ='"+ date2yyyymmdd( newDate())+"' where  billdate is null ",true);

    //凭证记录

    sql= `
    select  * 
    from (
        select distinct  concat( corpid , '-', ym ,'-',pzh ) as id ,  concat( corpid , '-', ym   ) as gguid  , corpid , ym  , pzh  from dzpz_pz   
        union 
        select distinct  concat( corpid , '-' ,  y*100+ m ,'-',pzh ) as id ,  concat ( corpid , '-' ,  y*100+ m ) as gguid , corpid ,   y*100+ m   as ym  ,pzh  from pzdjex 
            where y is not null and m is not null and  corpid is not null 
        ) a  where id is not null and corpid is not null  and ym is not null ${where} 
    order by id 
    
    `

    dbTransfer('', sql, 'pzbmx', 'id',true, 1000, '','', '', 0, 0, -5) ;

    runSQL("",`update pzbmx set createdate ='${date2yyyymmdd( newDate())}' where  createdate is null   ${where}`,true);

    runSQL("" , `create index  di_pzbmx_corpid_ym on  pzbmx ( corpid, ym) ` ,true);
    
    runSQL("" , `create unique index  ui_pzbmx_pzh on  pzbmx ( corpid, ym ,pzh) ` ,true);
    

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

    return 'over' ;


}


id: 663ab7c79932a08a57e3eec7
scriptid: 663879c89932a08a57e3eaea
tablename: app_template
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 10:31:19.000
script:
function cb_refresh_onClick() {
    showInfoPane("* 正在自动构造凭证清册");
    setTimeout(function () {
        runTask("autoRebuildPZB", {  }, function () {
            hideInfoPane();
            toastr.info("构建完成");
            smartRetrieve(book.sheet0,"pzb");
        });
    }, 500);
}


id: 663ab7c79932a08a57e3eecb
scriptid: 663879c89932a08a57e3eaea
tablename: app_template
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 10:31:30.000
script:
function cb_refresh_onClick() {
    showInfoPane("* 正在自动构造凭证清册");
    setTimeout(function () {
        runTask("autoRebuildPZB", {  }, function () {
            hideInfoPane();
            toastr.info("构建完成");
            smartRetrieve(book.sheet0,"pzb");
        });
    }, 500);
}


function cb_add_onClick()
{
    
}


id: 663ab7c79932a08a57e3eecf
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 10:33:11.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($pzbmx_ds.getString(0, "gguid"),
                            $pzbmx_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.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($pzbmx_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 pzh = [];

    let 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 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: 663ab7c79932a08a57e3eed3
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 10:33:30.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($pzbmx_ds.getString(0, "gguid"),
                            $pzbmx_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($pzbmx_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 pzh = [];

    let 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 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: 663ab7c79932a08a57e3eed8
scriptid: 663879c89932a08a57e3eaea
tablename: app_template
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 10:40:52.000
script:
function cb_refresh_onClick() {
    showInfoPane("* 正在自动构造凭证清册");
    setTimeout(function () {
        runTask("autoRebuildPZB", {  }, function () {
            hideInfoPane();
            toastr.info("构建完成");
            smartRetrieve(book.sheet0,"pzb");
        });
    }, 500);
}


function cb_add_onClick()
{

      book.sheet1.cells("corpid").setValue(null);
    book.sheet1.cells("y").setValue(null);
    book.sheet1.cells("m").setValue(null);
    

    book.sheet1.popup('fa fa-cog', '', 300, 105, true, true,
        {
            action1:
            {
                text: '确定',

                action: function () {
                    let corpid = book.sheet1.cells("corpid").getValueString();
                    let y = book.sheet1.cells("y").getValueInt();
                    let m = book.sheet1.cells("m").getValueInt();
                    
                    if( corpid=='')
                    {
                        toastr.info("请选择帐套");
                        return false; 
                    }

                    if( y==0)
                    {
                        toastr.info("请选择年");
                        return false; 
                    }
                    
                    if( m==0)
                    {
                        toastr.info("请选择月");
                        return false; 
                    }
                    
                    var ym= round( y*100 + m ,0) ; 
                    showInfoPane('*正在增加清册');

                    setTimeout(function () {
                        back_add ( corpid, y,m  ,function (ret) {
                                hideInfoPane();
                                toastr.info(ret.message);
                                smartRetrieve( book.sheet0 , "pzb"  ); 
                            });
                    }, 600);
                    return true;
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

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

        });

}


id: 663ae63b9932a08a57e3eef9
scriptid: 663a3aa59932a08a57e3eba1
tablename: app_script
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 10:45:09.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg)
{
    println( arg);
    var param= JSON.parse(arg);
    var corpid= param.corpid ||'';
    var ym = param.ym || ''; 

    var  minYM =  formatDate(  nextDate( newDate()  , -12 * 10 ,'month') , 'yyyyMM');
    
    var where=` and ym>= ${minYM} `;
    var moreUnion="";
    if( ym!='' ) 
    {

     where =  where  + ` and (corpid='${corpid}' and ym= ${ym} ) ` ;
     moreUnion =` union  select  '${corpid}-${ym}' as id , '${corpid}' as corpid ,  ${ym} as ym  from  dual  ";
     
    }
    //生成主记录

    var sql= ` select id , id as gguid , id as billno , 1 as userid , '管理员' as username , 0 as deleteflag ,
            corpid , ym  
            from (
                select distinct  concat( corpid , '-', ym ) as id , corpid , ym   from dzpz_pz   
            union 
                select distinct  concat ( corpid , '-' ,  y*100+ m ) as id , corpid ,   y*100+ m   as ym   from pzdjex 
            ${moreUnion}    
            ) a  
            where id is not null and corpid is not null  and ym is not null  ${where} 
            order by id 
        ` ; 

    dbTransfer('', sql, 'pzb', 'id',true, 1000, '','', '', 0, 0, -5) ;

    runSQL("","update pzb set billdate ='"+ date2yyyymmdd( newDate())+"' where  billdate is null ",true);

    //凭证记录

    sql= `
    select  * 
    from (
        select distinct  concat( corpid , '-', ym ,'-',pzh ) as id ,  concat( corpid , '-', ym   ) as gguid  , corpid , ym  , pzh  from dzpz_pz   
        union 
        select distinct  concat( corpid , '-' ,  y*100+ m ,'-',pzh ) as id ,  concat ( corpid , '-' ,  y*100+ m ) as gguid , corpid ,   y*100+ m   as ym  ,pzh  from pzdjex 
            where y is not null and m is not null and  corpid is not null 
        ) a  where id is not null and corpid is not null  and ym is not null ${where} 
    order by id 
    
    `

    dbTransfer('', sql, 'pzbmx', 'id',true, 1000, '','', '', 0, 0, -5) ;

    runSQL("",`update pzbmx set createdate ='${date2yyyymmdd( newDate())}' where  createdate is null   ${where}`,true);

    runSQL("" , `create index  di_pzbmx_corpid_ym on  pzbmx ( corpid, ym) ` ,true);
    
    runSQL("" , `create unique index  ui_pzbmx_pzh on  pzbmx ( corpid, ym ,pzh) ` ,true);
    

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

    return 'over' ;


}


id: 663ae63b9932a08a57e3ef0c
scriptid: 663879c89932a08a57e3eaea
tablename: app_template
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 10:46:29.000
script:
function cb_refresh_onClick() {
    showInfoPane("* 正在自动构造凭证清册");
    setTimeout(function () {
        runTask("autoRebuildPZB", {}, function () {
            hideInfoPane();
            toastr.info("构建完成");
            smartRetrieve(book.sheet0, "pzb");
        });
    }, 500);
}


function cb_add_onClick() {

    book.sheet1.cells("corpid").setValue(null);
    book.sheet1.cells("y").setValue(null);
    book.sheet1.cells("m").setValue(null);


    book.sheet1.popup('fa fa-cog', '', 300, 105, true, true,
        {
            action1:
            {
                text: '确定',

                action: function () {
                    let corpid = book.sheet1.cells("corpid").getValueString();
                    let y = book.sheet1.cells("y").getValueInt();
                    let m = book.sheet1.cells("m").getValueInt();

                    if (corpid == '') {
                        toastr.info("请选择帐套");
                        return false;
                    }

                    if (y == 0) {
                        toastr.info("请选择年");
                        return false;
                    }

                    if (m == 0) {
                        toastr.info("请选择月");
                        return false;
                    }

                    var ym = round(y * 100 + m, 0);
                    showInfoPane('*正在增加清册');

                    setTimeout(function () {
                        runTask("autoRebuildPZB", { corpid: corpid, ym: ym }, function () {
                            hideInfoPane();
                            toastr.info("构建完成");
                            smartRetrieve(book.sheet0, "pzb");
                        });
                    }, 600);
                    return true;
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

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

        });

}


id: 663ae63b9932a08a57e3ef1c
scriptid: 663879c89932a08a57e3eaea
tablename: app_template
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 10:47:43.000
script:
function cb_refresh_onClick() {
    showInfoPane("* 正在自动构造凭证清册");
    setTimeout(function () {
        runTask("autoRebuildPZB", {}, function () {
            hideInfoPane();
            toastr.info("构建完成");
            smartRetrieve(book.sheet0, "pzb");
        });
    }, 500);
}


function cb_new_onClick() {

    book.sheet1.cells("corpid").setValue(null);
    book.sheet1.cells("y").setValue(null);
    book.sheet1.cells("m").setValue(null);


    book.sheet1.popup('fa fa-cog', '', 300, 105, true, true,
        {
            action1:
            {
                text: '确定',

                action: function () {
                    let corpid = book.sheet1.cells("corpid").getValueString();
                    let y = book.sheet1.cells("y").getValueInt();
                    let m = book.sheet1.cells("m").getValueInt();

                    if (corpid == '') {
                        toastr.info("请选择帐套");
                        return false;
                    }

                    if (y == 0) {
                        toastr.info("请选择年");
                        return false;
                    }

                    if (m == 0) {
                        toastr.info("请选择月");
                        return false;
                    }

                    var ym = round(y * 100 + m, 0);
                    showInfoPane('*正在增加清册');

                    setTimeout(function () {
                        runTask("autoRebuildPZB", { corpid: corpid, ym: ym }, function () {
                            hideInfoPane();
                            toastr.info("构建完成");
                            smartRetrieve(book.sheet0, "pzb");
                        });
                    }, 600);
                    return true;
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

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

        });

}


id: 663ae63b9932a08a57e3ef21
scriptid: 663879c89932a08a57e3eaea
tablename: app_template
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 10:48:08.000
script:
function cb_refresh_onClick() {
    showInfoPane("* 正在自动构造凭证清册");
    setTimeout(function () {
        runTask("autoRebuildPZB", {}, function () {
            hideInfoPane();
            toastr.info("构建完成");
            smartRetrieve(book.sheet0, "pzb");
        });
    }, 500);
}


function cb_new_onClick() {

    book.sheet1.cells("corpid").setValue(null);
    book.sheet1.cells("y").setValue(null);
    book.sheet1.cells("m").setValue(null);


    book.sheet1.popup('fa fa-cog', '', 400, 105, true, true,
        {
            action1:
            {
                text: '确定',

                action: function () {
                    let corpid = book.sheet1.cells("corpid").getValueString();
                    let y = book.sheet1.cells("y").getValueInt();
                    let m = book.sheet1.cells("m").getValueInt();

                    if (corpid == '') {
                        toastr.info("请选择帐套");
                        return false;
                    }

                    if (y == 0) {
                        toastr.info("请选择年");
                        return false;
                    }

                    if (m == 0) {
                        toastr.info("请选择月");
                        return false;
                    }

                    var ym = round(y * 100 + m, 0);
                    showInfoPane('*正在增加清册');

                    setTimeout(function () {
                        runTask("autoRebuildPZB", { corpid: corpid, ym: ym }, function () {
                            hideInfoPane();
                            toastr.info("构建完成");
                            smartRetrieve(book.sheet0, "pzb");
                        });
                    }, 600);
                    return true;
                }
            },

            cancel:
            {
                text: '取消',

                action: function () {

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

        });

}


id: 663ae63b9932a08a57e3ef30
scriptid: 66382c259932a08a57e3e707
tablename: app_script
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 10:54:18.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_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: 663ae63b9932a08a57e3ef39
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 11:00:47.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($pzbmx_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 pzh = [];

    let 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 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: 663ae63b9932a08a57e3ef3d
scriptid: 66382c789932a08a57e3e70c
tablename: app_template
clientip: 115.205.0.84
username: sa
createdate: 2024.05.08 11:01:10.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 pzh = [];

    let 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 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 };


}


