<?php

$campo2 = "op_id";
$campo3 = "tipo_p_id";
$campo4 = "monto";
$campo5 = "detalle";
$campo6 = "id_bancosg";
$campo7 = "gift_number";
$campo8 = "gift_calc";
$campo9 = "id_forma";
$campo10 = "trig_unic";
$campo11 = "e_id";
$campo12 = "op_id_espe";
$campo13 = "mon_op";
$campo14 = "mon_taza_op";
$campo15 = "mon_id1";
$campo16 = "mon_taza1";
$campo17 = "mon_id2";
$campo18 = "mon_taza2";
$campo19 = "mon_id3";
$campo20 = "mon_taza3";
$campo21 = "syncprocesing";
$campo22 = "usermodify";
$campo23 = "useroption";

$valor = $campo2 . "," .
    $campo3 . "," .
    $campo4 . "," .
    $campo5 . "," .
    $campo6 . "," .
    $campo7 . "," .
    $campo8 . "," .
    $campo9 . "," .
    $campo10 . "," .
    $campo11 . "," .
    $campo12 . "," .
    $campo13 . "," .
    $campo14 . "," .
    $campo15 . "," .
    $campo16 . "," .
    $campo17 . "," .
    $campo18 . "," .
    $campo19 . "," .
    $campo20 . "," .
    $campo21 . "," .
    $campo22 . "," .
    $campo23;

$db_destino = $database;
$tabla_dest = "operacion_det_pago";
$db_tmp = "tmp";

$llave = "trig_unic";

$sqlop1 = "update  " . $db_destino . "." . $tabla_dest . ", ( select "
    . $valor . " from " . $db_tmp . "." . $_SESSION['unico'] . " "
    . " where " . $db_tmp . "." . $_SESSION['unico'] . "." . $llave
    . "  in (select " . $db_destino . "." . $tabla_dest . "."
    . $llave . " from " . $db_destino . "." . $tabla_dest
    . "  where " . $llave . " is not null  ) )b " . " set "

    . $tabla_dest . "." . $campo2 . "=b." . $campo2 . ",  "
    . $tabla_dest . "." . $campo3 . "=b." . $campo3 . ",  "
    . $tabla_dest . "." . $campo4 . "=b." . $campo4 . ",  "
    . $tabla_dest . "." . $campo5 . "=b." . $campo5 . ",  "
    . $tabla_dest . "." . $campo6 . "=b." . $campo6 . ",  "
    . $tabla_dest . "." . $campo7 . "=b." . $campo7 . ",  "
    . $tabla_dest . "." . $campo8 . "=b." . $campo8 . ",  "
    . $tabla_dest . "." . $campo9 . "=b." . $campo9 . ",  "
    . $tabla_dest . "." . $campo10 . "=b." . $campo10 . ",  "
    . $tabla_dest . "." . $campo11 . "=b." . $campo11 . ",  "
    . $tabla_dest . "." . $campo12 . "=b." . $campo12 . ",  "
    . $tabla_dest . "." . $campo13 . "=b." . $campo13 . ",  "
    . $tabla_dest . "." . $campo14 . "=b." . $campo14 . ",  "
    . $tabla_dest . "." . $campo15 . "=b." . $campo15 . ",  "
    . $tabla_dest . "." . $campo16 . "=b." . $campo16 . ",  "
    . $tabla_dest . "." . $campo17 . "=b." . $campo17 . ",  "
    . $tabla_dest . "." . $campo18 . "=b." . $campo18 . ",  "
    . $tabla_dest . "." . $campo19 . "=b." . $campo19 . ",  "
    . $tabla_dest . "." . $campo20 . "=b." . $campo20 . ",  "
    . $tabla_dest . "." . $campo21 . "=b." . $campo21 . ",  "
    . $tabla_dest . "." . $campo22 . "=b." . $campo22 . ",  "

    . $tabla_dest . "." . $campo23 . "=b." . $campo23 .

    " where "
    . $tabla_dest . "." . $llave . "=b." . $llave;

$sqlop2 = "insert into " . $db_destino . "." . $tabla_dest . " ( "
    . $valor . ") select " . $valor . " from " . $db_tmp . "."
    . $_SESSION['unico'] . "  where " . $llave . " not in (select " . $llave
    . " from " . $db_destino . "." . $tabla_dest . " " . " where "
    . $llave . " is not null)    group by " . $llave;

$sqlop2v2 = "insert into " . $db_destino . "." . $tabla_dest . " ( "
    . $valor . ") select " . $valor . " from " . $db_tmp . "."
    . $_SESSION['unico'] . " ON DUPLICATE KEY UPDATE op_id=values(op_id), tipo_p_id=values(tipo_p_id), monto=values(monto), detalle=values(detalle), id_bancosg=values(id_bancosg), gift_number=values(gift_number), gift_calc=values(gift_calc), id_forma=values(id_forma), trig_unic=values(trig_unic), e_id=values(e_id), op_id_espe=values(op_id_espe), mon_op=values(mon_op), mon_taza_op=values(mon_taza_op), mon_id1=values(mon_id1), mon_taza1=values(mon_taza1), mon_id2=values(mon_id2), mon_taza2=values(mon_taza2), mon_id3=values(mon_id3), mon_taza3=values(mon_taza3), syncprocesing=values(syncprocesing), usermodify=values(usermodify), useroption=values(useroption)";

?>