# app_script_history

id: 66bc0f82993294a6b3485b99
scriptid: 669dc60c9932df22f60cad3b
tablename: app_script
clientip: 122.234.136.22
username: sa
createdate: 2024.08.14 10:05:27.000
script:
function verifyGZL(gguid) {
    var count = getValueFromSQL2( "", `select count(0) from pz_yjd_pzh where gguid='${gguid}' and qsqx is not null and qsqx>0`  );
    println( 'verifyGZL count  ' + count ) 

    return count>0?'有凭证式延迟确认，不能提交结束工作流！':''
}


/**
 * 在已结束的流程被撤销结束后，触发本事件
 * 无需返回值
 * @param gguid 单据的gguid
 *
 */
//@comment (group=工作流事件,caption=x结束的流程被撤销结束后)
function afterFinishedWorkRollbacked ( gguid ) {
    runSQL("", ` update pz_yjd_pzh set state=0 where gguid='${gguid}' and  state=1`  );
}

/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");
    runSQL("", ` update pz_yjd_pzh set state=1 where gguid='${gguid}' and  ifnull(state, 0)=0`  );

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


function back_get_pzdj_gguid(from_id){
    return getStringFromSQL2( '', `select gguid from pzdj where from_id='${from_id}'`  ) 
}


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


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

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

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

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

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


function $back_build_sum(gguid) {


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

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

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

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


        });
    }

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


}


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

    $back_build_sum(gguid);
}


id: 66c29c33993294a6b3485ba9
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:13:23.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if(urlArgs.action=='view'){
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if(data.flow_instance_status.indexOf('结束')>0){
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    }else{
        
        if(data.flow_instance_status.indexOf('接收方签收确认')>0){
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;
            
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        }else{
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind= cell.bind;
    if( bind!=null &&  bind.dataSource=='q_pz_yjd_pzh' && bind.DBCol=='qsqx'){
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        if(qsqx < newValue){
            $pz_yjd_ds.setValue(0, 'qsqx', newValue);
        }

        if(newValue){

        }

    }


}


id: 66c29c33993294a6b3485bad
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:13:24.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if(urlArgs.action=='view'){
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if(data.flow_instance_status.indexOf('结束')>0){
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    }else{
        
        if(data.flow_instance_status.indexOf('接收方签收确认')>0){
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;
            
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        }else{
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind= cell.bind;
    if( bind!=null &&  bind.dataSource=='q_pz_yjd_pzh' && bind.DBCol=='qsqx'){
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        if(qsqx < newValue){
            $pz_yjd_ds.setValue(0, 'qsqx', newValue);
        }

        if(newValue){
            
        }

    }


}


id: 66c29c33993294a6b3485bb1
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:13:38.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        if (qsqx < newValue) {
            $pz_yjd_ds.setValue(0, 'qsqx', newValue);
        }

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

    }


}


id: 66c29c33993294a6b3485bb5
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:13:59.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        if (qsqx < newValue) {
            $pz_yjd_ds.setValue(0, 'qsqx', newValue);
        }

        if (newValue) {
            inputBox("提示", "请输入延长理由", "", "", function (val) {
                
            }, false, {}, 10);
        }

    }


}


id: 66c29c33993294a6b3485bc4
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:16:28.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 
        println('dayArr  ' + JSON.stringify(dayArr))
        println('createDate2  ' + JSON.stringify(createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5])))

        var confirmTime = formatDate(nextDate(createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]), item.qsqx != '0' ? item.qsqx : item.qsqx2), "yyyy.MM.dd HH:mm:ss");
        var nowTime = formatDate(currentDate(), "yyyy.MM.dd HH:mm:ss");

        println('confirmTime  ' + JSON.stringify(confirmTime))
        println('nowTime  ' + JSON.stringify(nowTime))

        if (nowTime >= confirmTime) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29c33993294a6b3485bcb
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:18:24.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 
        println('dayArr  ' + JSON.stringify(dayArr))
        println('createDate2  ' + JSON.stringify(createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5])))
        println('dayArr  ' + JSON.stringify(dayArr))
        println('nextDate  ' + JSON.stringify(nextDate(currentDate(),item.qsqx != '0' ? item.qsqx : item.qsqx2 )))

        var confirmTime = formatDate(nextDate(createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]), item.qsqx != '0' ? item.qsqx : item.qsqx2), "yyyy.MM.dd HH:mm:ss");
        var nowTime = formatDate(currentDate(), "yyyy.MM.dd HH:mm:ss");

        println('confirmTime  ' + JSON.stringify(confirmTime))
        println('nowTime  ' + JSON.stringify(nowTime))

        if (nowTime >= confirmTime) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29c33993294a6b3485bd2
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:18:42.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 
        println('dayArr  ' + JSON.stringify(dayArr))
        println('createDate2  ' + JSON.stringify(createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5])))
        println('nextDate  ' + JSON.stringify(nextDate(currentDate(),item.qsqx != '0' ? item.qsqx : item.qsqx2 )))

        var confirmTime = formatDate(nextDate(createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]), item.qsqx != '0' ? item.qsqx : item.qsqx2), "yyyy.MM.dd HH:mm:ss");
        var nowTime = formatDate(currentDate(), "yyyy.MM.dd HH:mm:ss");

        println('confirmTime  ' + JSON.stringify(confirmTime))
        println('nowTime  ' + JSON.stringify(nowTime))

        if (nowTime >= confirmTime) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29c33993294a6b3485bd8
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:18:51.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 
        println('dayArr  ' + JSON.stringify(dayArr))
        println('createDate2  ' + JSON.stringify(createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5])))
        println('nextDate  ' + JSON.stringify(nextDate(currentDate(), (item.qsqx != '0' ? item.qsqx : item.qsqx2 ) )))

        var confirmTime = formatDate(nextDate(createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]), item.qsqx != '0' ? item.qsqx : item.qsqx2), "yyyy.MM.dd HH:mm:ss");
        var nowTime = formatDate(currentDate(), "yyyy.MM.dd HH:mm:ss");

        println('confirmTime  ' + JSON.stringify(confirmTime))
        println('nowTime  ' + JSON.stringify(nowTime))

        if (nowTime >= confirmTime) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29c33993294a6b3485bdf
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:19:12.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 
        println('dayArr  ' + JSON.stringify(dayArr))
        println('createDate2  ' + JSON.stringify(createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5])))
        println('nextDate  ' + JSON.stringify(nextDate(newDate(), (item.qsqx != '0' ? item.qsqx : item.qsqx2 ) )))

        var confirmTime = formatDate(nextDate(createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]), item.qsqx != '0' ? item.qsqx : item.qsqx2), "yyyy.MM.dd HH:mm:ss");
        var nowTime = formatDate(currentDate(), "yyyy.MM.dd HH:mm:ss");

        println('confirmTime  ' + JSON.stringify(confirmTime))
        println('nowTime  ' + JSON.stringify(nowTime))

        if (nowTime >= confirmTime) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29c33993294a6b3485be6
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:23:00.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var count = daysBetween((nowTime), (confirmTime));
        println("count: " + count)


        if ( (item.qsqx != '0' ? item.qsqx : item.qsqx2 ) >= count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29c33993294a6b3485bed
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:23:32.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)


        if ( (item.qsqx != '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29c33993294a6b3485bf4
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:24:00.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("qsqx: " + (item.qsqx != '0' ? item.qsqx : item.qsqx2 ))


        if ( (item.qsqx != '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29c33993294a6b3485bfb
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:24:53.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("qsqx: " + item.qsqx)
        println("qsqx2: " + item.qsqx2  )


        if ( (item.qsqx != '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29c33993294a6b3485c02
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:25:18.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("qsqx: " + item.qsqx)
        println("qsqx2: " + item.qsqx2  )
        println("item.qsqx: " + (item.qsqx != '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx != '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29c33993294a6b3485c09
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:26:08.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("qsqx: " + item.qsqx)
        println("qsqx2: " + item.qsqx2  )
        println("item.qsqx: " + (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx != '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29f45993294a6b3485c10
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:26:54.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("qsqx: " + item.qsqx)
        println("qsqx2: " + item.qsqx2  )
        println("item.qsqx: " + (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29f45993294a6b3485c16
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:26:57.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("item.qsqx: " + (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    // return list

    return 'over';

}


id: 66c29f45993294a6b3485c2a
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:29:07.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("item.qsqx: " + (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })

    return list

    return 'over';

}


id: 66c29f45993294a6b3485c36
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:29:39.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("item.qsqx: " + (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)

    return list

    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workgguid = item.flow_process_definition_id.split(':')[0].replace('id_', '');

        println("workgguid  " + workgguid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workgguid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workgguid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workgguid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })


    return 'over';

}


id: 66c29f45993294a6b3485c3c
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:30:58.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("item.qsqx: " + (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workid = item.open_bill_with_url.split('&workspaceid=')[0].split('&id=')[1];

        println("workid  " + workid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })


    return 'over';

}


id: 66c29f45993294a6b3485c42
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:31:03.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("item.qsqx: " + (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)


    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workid = item.open_bill_with_url.split('&workspaceid=')[0].split('&id=')[1];

        println("workid  " + workid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })
    // return list

    return 'over';

}


id: 66c29f45993294a6b3485c4b
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:32:55.000
script:
function verifyGZL(gguid) {
    var count = getValueFromSQL2("", `select count(0) from pz_yjd_pzh where gguid='${gguid}' and state<>'1' and qsqx is not null and qsqx>0`);
    println('verifyGZL count  ' + count)

    return count > 0 ? '有凭证式延迟确认，不能提交结束工作流！' : ''
}


/**
 * 在已结束的流程被撤销结束后，触发本事件
 * 无需返回值
 * @param gguid 单据的gguid
 *
 */
//@comment (group=工作流事件,caption=x结束的流程被撤销结束后)
function afterFinishedWorkRollbacked ( gguid ) {
    runSQL("", ` update pz_yjd_pzh set state=0 where gguid='${gguid}' and  state=1`  );
}



/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

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

    runSQL("", ` update pz_yjd_pzh set state=1 where gguid='${gguid}' and  ifnull(state, 0)=0`);

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


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


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

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data) {

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

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

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


function $back_build_sum(gguid) {


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

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

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

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


        });
    }

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


}


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

    $back_build_sum(gguid);
}


id: 66c29f45993294a6b3485c59
scriptid: 669dc60c9932df22f60cad3b
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:34:24.000
script:
function verifyGZL(gguid) {
    var count = getValueFromSQL2( "", `select count(0) from pz_yjd_pzh where gguid='${gguid}' and state<>'1' and qsqx is not null and qsqx>0`  );
    println( 'verifyGZL count  ' + count ) 

    return count>0?'有凭证式延迟确认，不能提交结束工作流！':''
}


/**
 * 在已结束的流程被撤销结束后，触发本事件
 * 无需返回值
 * @param gguid 单据的gguid
 *
 */
//@comment (group=工作流事件,caption=x结束的流程被撤销结束后)
function afterFinishedWorkRollbacked ( gguid ) {
    runSQL("", ` update pz_yjd_pzh set state=0 where gguid='${gguid}' and  state=1`  );
}

/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");
    runSQL("", ` update pz_yjd_pzh set state=1 where gguid='${gguid}' and  ifnull(state, 0)=0`  );

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


function back_get_pzdj_gguid(from_id){
    return getStringFromSQL2( '', `select gguid from pzdj where from_id='${from_id}'`  ) 
}


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


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

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

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

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

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


function $back_build_sum(gguid) {


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

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

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

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


        });
    }

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


}


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

    $back_build_sum(gguid);
}


id: 66c29f45993294a6b3485c62
scriptid: 669dc6249932df22f60cc8cf
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:34:31.000
script:
function verifyGZL(gguid) {
    var count = getValueFromSQL2( "", `select count(0) from pz_yjd_pzh where gguid='${gguid}' and state<>'1' and qsqx is not null and qsqx>0`  );
    println( 'verifyGZL count  ' + count ) 

    return count>0?'有凭证式延迟确认，不能提交结束工作流！':''
}

/**
 * 在已结束的流程被撤销结束后，触发本事件
 * 无需返回值
 * @param gguid 单据的gguid
 *
 */
//@comment (group=工作流事件,caption=x结束的流程被撤销结束后)
function afterFinishedWorkRollbacked ( gguid ) {
    runSQL("", ` update pz_yjd_pzh set state=0 where gguid='${gguid}' and  state=1`  );
}

/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");
    runSQL("", ` update pz_yjd_pzh set state=1 where gguid='${gguid}' and  ifnull(state, 0)=0`  );

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


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


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

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

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

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

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


function $back_build_sum(gguid) {


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

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

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

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


        });
    }

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


}


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

    $back_build_sum(gguid);
}


id: 66c29f45993294a6b3485c6b
scriptid: 669dc6399932df22f60ce463
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:34:36.000
script:
function verifyGZL(gguid) {
    var count = getValueFromSQL2( "", `select count(0) from pz_yjd_pzh where gguid='${gguid}' and state<>'1' and qsqx is not null and qsqx>0`  );
    println( 'verifyGZL count  ' + count ) 

    return count>0?'有凭证式延迟确认，不能提交结束工作流！':''
}


/**
 * 在已结束的流程被撤销结束后，触发本事件
 * 无需返回值
 * @param gguid 单据的gguid
 *
 */
//@comment (group=工作流事件,caption=x结束的流程被撤销结束后)
function afterFinishedWorkRollbacked ( gguid ) {
    runSQL("", ` update pz_yjd_pzh set state=0 where gguid='${gguid}' and  state=1`  );
}



/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

 */
//@comment (group=工作流事件,caption=工作结束)
function onWorkFlowEnd(flow, node, gguid) {
    // println( flow.id) ; //流程定义的ID
    println(gguid + "工作结束了");
    runSQL("", ` update pz_yjd_pzh set state=1 where gguid='${gguid}' and  ifnull(state, 0)=0`  );

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


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


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

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data){

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

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

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


function $back_build_sum(gguid) {


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

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

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

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


        });
    }

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


}


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

    $back_build_sum(gguid);
}


id: 66c2a142993294a6b3485c71
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:34:59.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("item.qsqx: " + (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)

    return list

    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workid = item.open_bill_with_url.split('&workspaceid=')[0].split('&id=')[1];

        println("workid  " + workid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })
    // return list

    return 'over';

}


id: 66c2a142993294a6b3485c77
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:35:21.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        println("day_count: " + day_count)
        println("item.qsqx: " + (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)

    // return list

    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workid = item.open_bill_with_url.split('&workspaceid=')[0].split('&id=')[1];

        println("workid  " + workid)
        println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })
    // return list

    return 'over';

}


id: 66c2a1ca993294a6b3485ce8
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:38:51.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        if (qsqx < newValue) {
            $pz_yjd_ds.setValue(0, 'qsqx', newValue);
        }

        if (newValue) {
            inputBox("提示", "请输入延长理由", "", "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
            }, false, {}, 10);
        }

    }


}


id: 66c2a1ca993294a6b3485ced
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:44:31.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');

        if (newValue) {
            inputBox("提示", "请输入延长理由", "", "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                onContentReady:function(){
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                }
            }, 10);
        }

    }


}


id: 66c2a1ca993294a6b3485cf1
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:44:48.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');

        if (newValue) {
            inputBox("提示", "请输入延长理由", "", "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                onContentReady:function(){
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                }
            }, 10);
        }

    }


}


id: 66c2a1ca993294a6b3485cf5
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:44:52.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');

        if (newValue) {
            inputBox("提示", "请输入延长理由", "", "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
                
                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                onContentReady:function(){
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                }
            }, 10);
        }

    }


}


id: 66c2a1ca993294a6b3485cf9
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:46:41.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        console.log($pz_yjd_pzh_ds.getValue(innerRow, 'qsqx'))

        if (newValue) {
            inputBox("提示", "请输入延长理由", "", "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                onContentReady:function(){
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                }
            }, 10);
        }

    }


}


id: 66c2a1ca993294a6b3485cfd
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:47:14.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        console.log($q_pz_yjd_pzh_ds.getValue(innerRow, 'qsqx'))

        if (newValue) {
            inputBox("提示", "请输入延长理由", "", "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                onContentReady:function(){
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                }
            }, 10);
        }

    }


}


id: 66c2a1ca993294a6b3485d01
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:47:44.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        console.log($q_pz_yjd_pzh_ds.getValue(innerRow, 'qsqx'))

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                onContentReady:function(){
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                }
            }, 10);
        }

    }


}


id: 66c2a1ca993294a6b3485d05
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:48:11.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if(ycly == 'null') ycly = '';
        console.log($q_pz_yjd_pzh_ds.getValue(innerRow, 'qsqx'))

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                onContentReady:function(){
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                }
            }, 10);
        }

    }


}


id: 66c2a1ca993294a6b3485d09
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:48:45.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if(ycly == 'null' || ycly == null) ycly = '';
        console.log($q_pz_yjd_pzh_ds.getValue(innerRow, 'qsqx'))

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                onContentReady:function(){
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                }
            }, 10);
        }

    }


}


id: 66c2a1ca993294a6b3485d0d
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:49:31.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if(ycly == 'null' || ycly == null) ycly = '';
        console.log( sheet, cell, )

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                onContentReady:function(){
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                }
            }, 10);
        }

    }


}


id: 66c2a1ca993294a6b3485d11
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:51:28.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {
        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if(ycly == 'null' || ycly == null) ycly = '';
        console.log( sheet, cell, )

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                onContentReady:function(){
                    // $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                }
            }, 10);
        }

    }


}


id: 66c2a1ca993294a6b3485d15
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:56:41.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx') {
            var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
            var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
            if (ycly == 'null' || ycly == null) ycly = '';
            console.log(sheet, cell)

            if (newValue) {
                inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                    console.log(val)
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                    if (qsqx < newValue) {
                        $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                    }
                }, false, {
                        onContentReady: function () {
                            // $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                        }
                    }, 10);
            }
        }

    }


}


/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    console.log(row + "  " + col + "  value= " + newValue);

}


id: 66c2a1ca993294a6b3485d19
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:56:47.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx') {
            var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
            var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
            if (ycly == 'null' || ycly == null) ycly = '';
            console.log(sheet, cell)

            if (newValue) {
                inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                    console.log(val)
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                    if (qsqx < newValue) {
                        $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                    }
                }, false, {
                        onContentReady: function () {
                            $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                        }
                    }, 10);
            }
        }

    }


}


/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    console.log(row + "  " + col + "  value= " + newValue);

}


id: 66c2a1ca993294a6b3485d1d
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 09:57:14.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';
        console.log(sheet, cell)

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                    onContentReady: function () {
                        $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', 0);
                    }
                }, 10);
        }

    }


}


/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    console.log(row + "  " + col + "  value= " + newValue);

}


id: 66c2a1ca993294a6b3485d21
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:00:07.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';
        window.qsqx_change = true;
        console.log(sheet, cell)

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                    onContentReady: function () {
                        $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    }
                }, 10);
        }

    }


}


/**
 * 数据集中的数据发生变化
 * @param dsname 数据集名称
 * @param row   数据行号
 * @param col    字段名
 * @param oldValue   原值
 * @param newValue  新值
 */
function itemChanged(dsname, row, col, oldValue, newValue) {
    console.log(row + "  " + col + "  value= " + newValue);

    if(dsname == 'q_pz_yjd_pzh' && col=='qsqx' && window.qsqx_change){
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a1ca993294a6b3485d25
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:00:46.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';
        window.qsqx_change = true;

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                console.log(val)
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                    onContentReady: function () {
                        $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    }
                }, 10);
        }

    }


}


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

    if(dsname == 'q_pz_yjd_pzh' && col=='qsqx' && window.qsqx_change){
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a1ca993294a6b3485d29
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:00:48.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';
        window.qsqx_change = true;

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                    onContentReady: function () {
                        $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    }
                }, 10);
        }

    }


}


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

    if(dsname == 'q_pz_yjd_pzh' && col=='qsqx' && window.qsqx_change){
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a1ca993294a6b3485d2d
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:03:54.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';
        window.qsqx_change = true;

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

                if (qsqx < newValue) {
                    $pz_yjd_ds.setValue(0, 'qsqx', newValue);
                }
            }, false, {
                    onContentReady: function () {
                        $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    }
                }, 10);
        }

    }


}

function chang_qsqx(){
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i=0;i<count;i++){
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if(qsqx<qsqx1){
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if(dsname == 'q_pz_yjd_pzh' && col=='qsqx' && window.qsqx_change){
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a1ca993294a6b3485d31
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:03:58.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';
        window.qsqx_change = true;

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);

            }, false, {
                    onContentReady: function () {
                        $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    }
                }, 10);
        }

    }


}

function chang_qsqx(){
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i=0;i<count;i++){
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if(qsqx<qsqx1){
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if(dsname == 'q_pz_yjd_pzh' && col=='qsqx' && window.qsqx_change){
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a1ca993294a6b3485d35
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:04:01.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';
        window.qsqx_change = true;

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
            }, false, {
                    onContentReady: function () {
                        $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    }
                }, 10);
        }

    }


}

function chang_qsqx(){
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i=0;i<count;i++){
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if(qsqx<qsqx1){
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if(dsname == 'q_pz_yjd_pzh' && col=='qsqx' && window.qsqx_change){
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d39
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:04:09.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';
        window.qsqx_change = true;

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                }
            }, 10);
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d3e
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:07:13.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        var qsqx_old = $q_pz_yjd_pzh_ds.getValue(innerRow, 'qsqx', false);
        console.log(qsqx_old, '============')
        window.qsqx_change = true;

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                }
            }, 10);
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d42
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:07:35.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        var qsqx_old = $q_pz_yjd_pzh_ds.getValue(innerRow, 'qsqx', true);
        console.log(qsqx_old, '============')
        window.qsqx_change = true;

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                }
            }, 10);
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d46
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:09:20.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        // var qsqx_old = $q_pz_yjd_pzh_ds.getValue(innerRow, 'qsqx', true);
        // console.log(qsqx_old, '============')
        window.qsqx_change = true;

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                }
            }, 10);
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d4a
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:10:33.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                }
            }, 10);
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d4e
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:11:22.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue) {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    window.qsqx_old = 0;
                }
            }, 10);
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d56
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:15:18.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue>'0') {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    window.qsqx_old = 0;
                }
            }, 10);
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d5a
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:16:14.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue>'0') {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
                chang_qsqx();
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    window.qsqx_old = 0;
                }
            }, 10);
        }else{
            $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', '');
            chang_qsqx();
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d5f
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:16:50.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if(urlArgs.action=='view'){
        
        book.getWorkSheet('main').getBrick('cb_import_pz').visible = false;

        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if(data.flow_instance_status.indexOf('结束')>0){
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    }else{
        
        if(data.flow_instance_status.indexOf('接收方签收确认')>0){
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;
            
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else{
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}

//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick() {
    var p_gguid = currentGUID();

    back_get_pzdj_gguid(p_gguid, function(gguid){
        $.dialog({
            title: '凭证资料导入',
            boxWidth: '1000px',
            useBootstrap: false,
            content: `<iframe  style="width:100%;height:400px; border:0" src="billedit?id=pzdj${gguid?`&action=edit&gguid=${gguid}`:'&action=new'}&from_id=${p_gguid}"></iframe>`
        });
    })

    // let dlg= floatDialog( "凭证资料导入" ,"billlist" , "pzdj" , 1000,500, {} , "listToolbarVisible=true&editToolbarVisible=true&from_id="+currentGUID()  , function(val){alert(val);});
}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

            });
        }, 100);

    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue>'0') {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
                chang_qsqx();
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    window.qsqx_old = 0;
                }
            }, 10);
        }else{
            $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', '');
            chang_qsqx();
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d64
scriptid: 669dc6249932df22f60cc8eb
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:17:01.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if(urlArgs.action=='view'){
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if(data.flow_instance_status.indexOf('结束')>0){
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    }else{

        if(data.flow_instance_status.indexOf('接收方签收确认')>0){
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;
            
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        }else{
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }


}

//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

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

function cb_import_onClick() {

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

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


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


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

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

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

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


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

            });
        }, 100);

    });

}


/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue>'0') {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
                chang_qsqx();
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    window.qsqx_old = 0;
                }
            }, 10);
        }else{
            $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', '');
            chang_qsqx();
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d69
scriptid: 669dc6399932df22f60ce47f
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:17:08.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);

    if(urlArgs.action=='view'){
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if(data.flow_instance_status.indexOf('结束')>0){
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    }else{

        if(data.flow_instance_status.indexOf('接收方签收确认')>0){
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;
            
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        }else{
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }
        
    }

}

//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

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

function cb_import_onClick() {

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

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


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


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

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

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

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


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

            });
        }, 100);

    });

}


/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue>'0') {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
                chang_qsqx();
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    window.qsqx_old = 0;
                }
            }, 10);
        }else{
            $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', '');
            chang_qsqx();
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c2a819993294a6b3485d8e
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:25:24.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        // println("day_count: " + day_count)
        // println("item.qsqx: " + (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            // println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)

    // return list

    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workid = item.open_bill_with_url.split('&workspaceid=')[0].split('&id=')[1];

        // println("workid  " + workid)
        // println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            println(gguid);
            var t = taskInfoForWork(workid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })
    // return list

    return 'over';

}


id: 66c2a819993294a6b3485d94
scriptid: 66bb02cf993294a6b3485671
tablename: app_script
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 10:25:36.000
script:
/**
 * 脚本中心的脚本，以 main函数为执行入口，相关的参数放在arg中，它是一个JSON字符串化后的数据
 *
 */
function main(arg) {
    println(arg);
    var param = JSON.parse(arg);

    var dsn = "";
    var sql = `select a.*, b.flow_instance_starttime, b.qsqx as qsqx2 from pz_yjd_pzh a left join pz_yjd b on a.gguid=b.gguid where b.flow_instance_state = 0 and b.flow_instance_starttime is not null and a.state=0`;
    // var list = getListFromSQL2( dsn, sql);


    // var list = getListFromSQL2( '', `select * from  pz_yjd `) 
    // var list = getListFromSQL2( '', `select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid`) 

    // return list

    var ds = newDataStore(dsn, sql);
    ds.retrieve();
    println("select : " + ds.getSelectLastRetrieved())
    var count = ds.getRowCount();
    println('count: ' + count)
    for (var i = 0; i < count; i++) {
        var item = JSON.parse(ds.getJSONRow(i));
        var dayArr = item.flow_instance_starttime.replace(/ /g, '-').replace(/:/g, '-').replace(/\./g, '-').split('-');
        // println( 'item.flow_instance_starttime  ' + JSON.stringify(item.flow_instance_starttime) ) 

        var confirmTime = createDate2(dayArr[0], dayArr[1], dayArr[2], dayArr[3], dayArr[4], dayArr[5]);
        var nowTime = currentDate();
        
        // 开始时间和结束时间相差多少天
        var day_count = daysBetween((nowTime), (confirmTime));
        // println("day_count: " + day_count)
        // println("item.qsqx: " + (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 )  )


        if ( (item.qsqx/1 > '0' ? item.qsqx : item.qsqx2 ) >= day_count) {
            // println('  item.id ' + item.id)
            runSQL(dsn, `update pz_yjd_pzh set state=1 where id='${item.id}'`);
        }
    }


    var list = getListFromSQL2('', `select * from  pz_yjd a left join (select gguid, sum(case when ifnull(state,0)=0 then 1 else 0 end) as count from  pz_yjd_pzh  group by gguid) b on a.gguid=b.gguid where  a.flow_instance_state = 0 and b.count=0 `)

    // return list

    list.forEach(item => {
        println("延长确认，自动确认");
        var gguid = item.gguid, workid = item.open_bill_with_url.split('&workspaceid=')[0].split('&id=')[1];

        // println("workid  " + workid)
        // println("gguid  " + gguid)

        //递交结束
        var loopCount = 0;
        while (loopCount < 10) {
            loopCount++;
            // println(gguid);
            var t = taskInfoForWork(workid, gguid);
            println(JSON.stringify(t));
            if (t.taskList.length == 0) break;
            //将任务递交下去，如果任务需要签收，则先签收     
            for (var i = 0; i < t.taskList.length; i++) {
                var task = t.taskList[i];

                //可以递交，那么递交下去
                if (task.canSubmit) println(submitWork(workid, gguid, task.taskId));
                //需要先签收 ，那么以第一个候选人签收它
                if (task.canClaim) claimWork(workid, gguid, task.taskId, task.candidateUserList[0].userId);

            }


        }

    })
    // return list

    return 'over';

}


id: 66c2dcd7993294a6b3485f7a
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 122.235.243.224
username: sa
createdate: 2024.08.19 14:04:33.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;


console.log(data.flow_instance_status.indexOf('结束'), '===========')
        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue>'0') {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
                chang_qsqx();
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    window.qsqx_old = 0;
                }
            }, 10);
        }else{
            $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', '');
            chang_qsqx();
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c310cd993294a6b3485fe8
scriptid: 60ac750d5db2f5d22859c4c0
tablename: app_script
clientip: 125.119.204.23
username: sa
createdate: 2024.08.20 12:39:51.000
script:
/*
凭证中的某个附件移除，并还原到待归档图片池中
  1 记录移除
  2 移到 待归档图片池中
  3  几个标记数据还愿

*/

function main(arg) {

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

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


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

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


    var row = dzpz_imgpool_fileupload_ds.insertRow(9999);

    cloneRow(dzpz_pzfj_ds, dzpz_imgpool_fileupload_ds, row);

    //数据调整


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

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

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

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

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

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

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

    return { success: false, message: err };

}

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


id: 66c310cd993294a6b3485fee
scriptid: 60ac750d5db2f5d22859c4c0
tablename: app_script
clientip: 125.119.204.23
username: sa
createdate: 2024.08.20 13:47:25.000
script:
/*
凭证中的某个附件移除，并还原到待归档图片池中
  1 记录移除
  2 移到 待归档图片池中
  3  几个标记数据还愿

*/

function main(arg) {

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

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


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

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


    var row = dzpz_imgpool_fileupload_ds.insertRow(9999);

    cloneRow(dzpz_pzfj_ds, dzpz_imgpool_fileupload_ds, row);

    //数据调整


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

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

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

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

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

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

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

    return { success: false, message: err };

}

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


id: 66c42dfa993294a6b3485ff4
scriptid: 60ac750d5db2f5d22859c4c0
tablename: app_script
clientip: 125.119.204.23
username: sa
createdate: 2024.08.20 13:47:38.000
script:
/*
凭证中的某个附件移除，并还原到待归档图片池中
  1 记录移除
  2 移到 待归档图片池中
  3  几个标记数据还愿

*/

function main(arg) {

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

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


    var dzpz_pzfj_ds = newDataStore("", "select * from dzpz_pzfj "); //凭证附件
    dzpz_pzfj_ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    dzpz_pzfj_ds.retrieve(" id='"+ id+"' ");
    println( dzpz_pzfj_ds.getJSONRow(0,true));

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

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


    var row = dzpz_imgpool_fileupload_ds.insertRow(9999);

    cloneRow(dzpz_pzfj_ds, dzpz_imgpool_fileupload_ds, row);

    //数据调整


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

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

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

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

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

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

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

    return { success: false, message: err };

}

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


id: 66c42dfa993294a6b3485ffa
scriptid: 60ac750d5db2f5d22859c4c0
tablename: app_script
clientip: 125.119.204.23
username: sa
createdate: 2024.08.20 13:49:20.000
script:
/*
凭证中的某个附件移除，并还原到待归档图片池中
  1 记录移除
  2 移到 待归档图片池中
  3  几个标记数据还愿

*/

function main(arg) {

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

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


    var dzpz_pzfj_ds = newDataStore("", "select * from dzpz_pzfj "); //凭证附件
    dzpz_pzfj_ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    dzpz_pzfj_ds.retrieve(" id='"+ id+"' ");
    println( dzpz_pzfj_ds.getJSONRow(0,true));

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

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


    var row = dzpz_imgpool_fileupload_ds.insertRow(9999);

    cloneRow(dzpz_pzfj_ds, dzpz_imgpool_fileupload_ds, row);

    //数据调整


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

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

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

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

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

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

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

    return { success: false, message: err };

}

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


id: 66c42dfa993294a6b3486007
scriptid: 60ac750d5db2f5d22859c4c0
tablename: app_script
clientip: 125.119.204.23
username: sa
createdate: 2024.08.20 13:56:18.000
script:
/*
凭证中的某个附件移除，并还原到待归档图片池中
  1 记录移除
  2 移到 待归档图片池中
  3  几个标记数据还愿

*/

function main(arg) {

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

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


    var dzpz_pzfj_ds = newDataStore("", "select * from dzpz_pzfj "); //凭证附件
    dzpz_pzfj_ds.setUpdateProperty("dzpz_pzfj", "id", "*", "id");
    dzpz_pzfj_ds.retrieve(" id='"+ id+"' ");
    println( dzpz_pzfj_ds.getJSONRow(0,true));

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

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


    var row = dzpz_imgpool_fileupload_ds.insertRow(9999);

    cloneRow(dzpz_pzfj_ds, dzpz_imgpool_fileupload_ds, row);

    //数据调整


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

    dzpz_imgpool_fileupload_ds.setValue(row, "gguid", gguid);
    dzpz_imgpool_fileupload_ds.setValue(row, "info2", ''); // 不然图片池中不会显示它
    
    dzpz_imgpool_fileupload_ds.setValue(row, "tablename", "dzpz_imgpool");
    

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

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

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

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

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

    return { success: false, message: err };

}

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


id: 66c430e3993294a6b3486083
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 125.119.204.23
username: sa
createdate: 2024.08.20 17:04:16.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;


        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 <= data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue>'0') {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
                chang_qsqx();
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    window.qsqx_old = 0;
                }
            }, 10);
        }else{
            $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', '');
            chang_qsqx();
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c430e3993294a6b3486087
scriptid: 662a47879932b5035f32efb0
tablename: app_template
clientip: 125.119.204.23
username: sa
createdate: 2024.08.20 17:07:20.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if (urlArgs.action == 'view') {
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;


        if (data.flow_instance_status.indexOf('结束') > 0) {
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    } else {

        if (data.flow_instance_status.indexOf('接收方签收确认') > 0) {
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;

            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else {
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 < data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

                });
            }, 100);

        });
    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue>'0') {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
                chang_qsqx();
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    window.qsqx_old = 0;
                }
            }, 10);
        }else{
            $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', '');
            chang_qsqx();
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c430e3993294a6b3486090
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 125.119.204.23
username: sa
createdate: 2024.08.20 17:09:56.000
script:
function verifyGZL(gguid) {
    var count = getValueFromSQL2("", `select count(0) from pz_yjd_pzh where gguid='${gguid}' and state<>'1' and qsqx is not null and qsqx>0`);
    println('verifyGZL count  ' + count)

    return count > 0 ? '有凭证式延迟确认，不能提交结束工作流！' : ''
}


/**
 * 在已结束的流程被撤销结束后，触发本事件
 * 无需返回值
 * @param gguid 单据的gguid
 *
 */
//@comment (group=工作流事件,caption=x结束的流程被撤销结束后)
function afterFinishedWorkRollbacked ( gguid ) {
    runSQL("", ` update pz_yjd_pzh set state=0 where gguid='${gguid}' and  state=1`  );
}



/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

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

    runSQL("", ` update pz_yjd_pzh set state=1 where gguid='${gguid}' and  ifnull(state, 0)=0`);

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


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

    println( 'count  ' + (count)) 


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

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data) {

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

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

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


function $back_build_sum(gguid) {


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

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

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

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


        });
    }

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


}


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

    $back_build_sum(gguid);
}


id: 66c430e3993294a6b348609c
scriptid: 662a47879932b5035f32efab
tablename: app_script
clientip: 125.119.204.23
username: sa
createdate: 2024.08.20 17:15:57.000
script:
function verifyGZL(gguid) {
    var count = getValueFromSQL2("", `select count(0) from pz_yjd_pzh where gguid='${gguid}' and state<>'1' and qsqx is not null and qsqx>0`);
    println('verifyGZL count  ' + count)

    return count > 0 ? '有凭证式延迟确认，不能提交结束工作流！' : ''
}


/**
 * 在已结束的流程被撤销结束后，触发本事件
 * 无需返回值
 * @param gguid 单据的gguid
 *
 */
//@comment (group=工作流事件,caption=x结束的流程被撤销结束后)
function afterFinishedWorkRollbacked ( gguid ) {
    runSQL("", ` update pz_yjd_pzh set state=0 where gguid='${gguid}' and  state=1`  );
}



/**
 * 工作结束
 * @param flow 流程定义
 * @param node 开始节点
 * @param gguid 单据的gguid

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

    runSQL("", ` update pz_yjd_pzh set state=1 where gguid='${gguid}' and  ifnull(state, 0)=0`);

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


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

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

    back_build_sum();
    return { success: true };

}

function back_import_pzh_data(data) {

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

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

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


function $back_build_sum(gguid) {


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

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

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

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


        });
    }

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


}


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

    $back_build_sum(gguid);
}


id: 66c430e3993294a6b34860a7
scriptid: 669dc60c9932df22f60cad57
tablename: app_template
clientip: 125.119.204.23
username: sa
createdate: 2024.08.20 17:16:33.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if(urlArgs.action=='view'){
        
        book.getWorkSheet('main').getBrick('cb_import_pz').visible = false;

        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if(data.flow_instance_status.indexOf('结束')>0){
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    }else{
        
        if(data.flow_instance_status.indexOf('接收方签收确认')>0){
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;
            
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        } else{
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }

}

//@comment (group=按钮,caption=凭证资料导入)
function cb_import_pz_onClick() {
    var p_gguid = currentGUID();

    back_get_pzdj_gguid(p_gguid, function(gguid){
        $.dialog({
            title: '凭证资料导入',
            boxWidth: '1000px',
            useBootstrap: false,
            content: `<iframe  style="width:100%;height:400px; border:0" src="billedit?id=pzdj${gguid?`&action=edit&gguid=${gguid}`:'&action=new'}&from_id=${p_gguid}"></iframe>`
        });
    })

    // let dlg= floatDialog( "凭证资料导入" ,"billlist" , "pzdj" , 1000,500, {} , "listToolbarVisible=true&editToolbarVisible=true&from_id="+currentGUID()  , function(val){alert(val);});
}


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

    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

    if (data.pzh2 < data.pzh1) {
        toastr.error('终止凭证号要比起始凭证号大');
        return false;
    }

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

function cb_import_onClick() {

    var sheet = book.getWorkSheet('导入凭证号');

    sheet.cells('ny').setValue('');
    sheet.cells('pzh').setValue('');

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


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


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

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

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


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


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

            });
        }, 100);

    });

}

/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue>'0') {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
                chang_qsqx();
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    window.qsqx_old = 0;
                }
            }, 10);
        }else{
            $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', '');
            chang_qsqx();
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


id: 66c430e3993294a6b34860ac
scriptid: 669dc6249932df22f60cc8eb
tablename: app_template
clientip: 125.119.204.23
username: sa
createdate: 2024.08.20 17:16:41.000
script:
/**
 * 一个单据打开，
 * 1 先对类型为“表”的结果集做数据异步检索
 * 2 全部表检索完成之后，再执行 formOpen 事件
 * 3 再根据  actio 执行 newOpen/viewOpen/editOpen 之一
 * 4 再执行  afterOpen
 * 5 对类型为“结果集”的且需要自动检索的结果集，做异步检索
 * 6 异步检索完成后，最后执行  formOpenOver 事件
 */
//@comment (group=表单事件,caption=表单初始化全部完成之后)
function formOpenOver() {
    var data = $pz_yjd_ds.getJSON(0);
    // console.log(data)

    if(urlArgs.action=='view'){
        book.getWorkSheet('汇总').getBrick('cb_add_pz').visible = false;
        book.getWorkSheet('清单').getBrick('cb_import').visible = false;
        book.getWorkSheet('清单').getBrick('cb_buildsum').visible = false;

        book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
        book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;


        book.getWorkSheet('清单').cells('qsqx').visible = false;
        book.getWorkSheet('清单').cells('qsqx').clickable = false;

        book.getWorkSheet('清单').cells('state').visible = false;
        book.getWorkSheet('清单').cells('state').clickable = false;

        if(data.flow_instance_status.indexOf('结束')>0){
            book.getWorkSheet('清单').cells('qsqx').visible = true;
            book.getWorkSheet('清单').cells('state').visible = true;
        }

    }else{

        if(data.flow_instance_status.indexOf('接收方签收确认')>0){
            book.getWorkSheet('清单').cells('qsqx').editable = true;
            book.getWorkSheet('清单').cells('state').editable = true;
            
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = false;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = false;
        }else{
            book.getWorkSheet('清单').cells('c_db_deleterow').visible = true;
            book.getWorkSheet('清单').cells('c_db_deleterow').clickable = true;
        }

    }


}

//@comment (group=按钮,caption=添加凭证号)
function cb_add_pz_onClick() {
    var sheet = book.getWorkSheet('添加凭证号');
    
    sheet.cells('ny').setValue('');
    sheet.cells('pzh1').setValue('');
    sheet.cells('pzh2').setValue('');

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

}

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

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

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

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

function cb_import_onClick() {

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

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


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


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

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

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

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


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

            });
        }, 100);

    });

}


/**
 * 单元格因为被编辑而改变。当用户通过编辑单元的值而让单元格发生值改变时本事件被触发。
 * 注意，当使用脚本 sheet.cells(row,col).setValue ( value) 来改变单元格的值时，本事件并不触发
 * @param sheet
 * @param cell
 * @param newValue
 * @param innerRow   当单元格没有绑定数据库或绑定到单行数据库时，本参数无意义。如果绑定一个
 * 多行数据库，则表示该单元所绑定的字段的第 innerRow行发生变化
 */
function cellValueChangedByEdit(sheet, cell, newValue, innerRow) {

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

    }

    //通过数据库绑定情况来判断
    let bind = cell.bind;
    if (bind != null && bind.dataSource == 'q_pz_yjd_pzh' && bind.DBCol == 'qsqx') {

        var qsqx = $pz_yjd_ds.getValue(0, 'qsqx');
        var ycly = $q_pz_yjd_pzh_ds.getValue(innerRow, 'ycly');
        if (ycly == 'null' || ycly == null) ycly = '';

        window.qsqx_change = true;

        if (newValue>'0') {
            inputBox("提示", "请输入延长理由", ycly, "", function (val) {
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', val);
                $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', newValue);
                chang_qsqx();
            }, false, {
                onContentReady: function () {
                    $q_pz_yjd_pzh_ds.setValue(innerRow, 'qsqx', window.qsqx_old);
                    window.qsqx_old = 0;
                }
            }, 10);
        }else{
            $q_pz_yjd_pzh_ds.setValue(innerRow, 'ycly', '');
            chang_qsqx();
        }

    }


}

function chang_qsqx() {
    var count = $q_pz_yjd_pzh_ds.getRowCount();
    var qsqx = 3;
    for (var i = 0; i < count; i++) {
        var qsqx1 = $q_pz_yjd_pzh_ds.getValue(i, 'qsqx');
        if (qsqx < qsqx1) {
            qsqx = qsqx1;
        }
    }

    $pz_yjd_ds.setValue(0, 'qsqx', qsqx);
}


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

    if (dsname == 'q_pz_yjd_pzh' && col == 'qsqx' && window.qsqx_change) {
        window.qsqx_old = oldValue;
        window.qsqx_change = false;
    }

}


