Duplicate a purchase order :
ROWID=xxx
NEWREF="(PROV-CL-$ROWID-$RANDOM)"
rm -f /tmp/llx.raw &&
mysql dolibarr -e "SELECT * FROM llx_commande_fournisseur WHERE rowid=$ROWID INTO OUTFILE '/tmp/llx.raw'" &&
sed -i "s/^$ROWID\t/\\\\N\t/" /tmp/llx.raw &&
sed -i "s/\tPO[^\t]*\t/\t$NEWREF\t/" /tmp/llx.raw &&
mysql dolibarr -e "LOAD DATA INFILE '/tmp/llx.raw' INTO TABLE llx_commande_fournisseur" &&
NEWID="$(mysql dolibarr -Nsr -e "SELECT rowid FROM llx_commande_fournisseur WHERE ref='$NEWREF'")" &&
[ "$(mysql dolibarr -Nsr -e "SELECT COUNT(*) FROM llx_commande_fournisseur WHERE ref='$NEWREF'")" = "1" ] &&
mysql dolibarr -e "UPDATE llx_commande_fournisseur SET fk_statut=0 WHERE rowid=$NEWID" &&
rm -f /tmp/llx.raw &&
mysql dolibarr -e "SELECT * FROM llx_commande_fournisseurdet where fk_commande=$ROWID INTO OUTFILE '/tmp/llx.raw'" &&
sed -i "s/^[^\t]*\t$ROWID\t/\\\\N\t$NEWID\t/" /tmp/llx.raw &&
mysql dolibarr -e "LOAD DATA INFILE '/tmp/llx.raw' INTO TABLE llx_commande_fournisseurdet" &&
echo "https://dolibarr.sipartech.com/fourn/commande/fiche.php?id=$NEWID"